从Atlas到Microsoft ASP.NET AJAX(9) - Using the Value-add Scripts
版权声明:原创作品,如需转载,请与作者联系。否则将追究法律责任。 |
Using the Value-add Scripts 在CTP版本中,您只需简单地将一个ScriptManager控件加到页面中,默认的CTP核心功能(Atlas.js)就被添加了。不过其它一些脚本是可选的,例如AtlasUIGlitz.js文件。如果您要使用它们,则需要手动地将其加入ScriptManager的references中,或者将他们定义在XML-Script的<refereces />里。 在RTM版本中,为了使用Value-add里的功能,您必须在ScriptManager中添加特定的脚本引用。下面的例子展示了如何引用Value-add中定义的所有脚本。
<asp:ScriptManager runat=”server” id=”ScriptManager1”> <Scripts> <asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="Microsoft.Web.Resources.ScriptLibrary.PreviewScript.js"/> <asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="Microsoft.Web.Resources.ScriptLibrary.PreviewGlitz.js"/> <asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="Microsoft.Web.Resources.ScriptLibrary.PreviewDragDrop.js"/> </Scripts> </ScriptManager> Client-based and Server-based Types 定义在Value-add脚本中的类型从CTP版本中的Sys.*命名空间转移到了Sys.Preview.*中。这确保了功能上的明显区别。从CTP转移到Value-add脚本的开发人员需要更新他们的JavaScript代码。例如,Sys.Services.Components.Profile组件现在已经变成了Sys.Preview.Services.Components.Profile。 相似地,使用CTP版本中服务器控件的开发人员在转移到Value-add时,则必须更新Web.config文件,以使用新的命名空间:Microsoft.Web.Preview.*。例如,Microsoft.Web.UI.Controls.DragOverlayExtender现在已经变成了Microsoft.Web.Preview.UI.Controls.DragOverlayExtender。 XML-Script 在Value-add包内依旧能够使用XML-Script,但是由于RTM版本的影响,必须作一些改变。另外,XML-Script的功能也得到了增强。 XML-Script的标签名直接使用了类型名称,在CTP版本中内置的下列标签在Value-add包中被改变了: <opacity /> <layout /> <autoComplete /> <setProperty /> <invokeMethod /> <serviceMethod /> <postback /> <select /> 在Value-add包中,上述标签名变成了: <opacityBehavior /> <layoutBehavior /> <autoCompleteBehavior /> <setPropertyAction /> <invokeMethodAction /> <serviceMethodRequest /> <postbackAction /> <selector /> Defining Tag Prefixes XML标签依旧使用内置的脚本前缀。另外,对自定义前缀的支持被增强了,它使用了如下的语法。这允许开发人员使用逗号来分隔命名空间的标记。 <script type="text/xml-script"> <page xmlns:script="http://schemas.microsoft.com/xml-script/2005" xmlns="JavaScript: Sys.UI, Sys"> <components> ... </components> </page> </script> Creating Declarative Bindings CTP版本中的Binding被转移到了Value-add脚本中,并且它能够支持在各种级别中使用,而无须嵌套在某个特定的控件中。当它被嵌套在某个控件中时,binding会从它父控件得到上下文或者数据源。下面的代码能够同时在CTP和Value-add中正确使用binding: <script type="text/xml-script"> <page xmlns:script="http://schemas.microsoft.com/xml-script/2005"> <components> <textbox id="Name" /> <label id="FirstName"> <bindings> <binding dataContext="Name" dataPath="text" property="text"/> </bindings> </label> </components> </page> </script> 在Value-add包中,binding的propertyKey属性能够支持“.”的使用,这允许您指定某个特定的子属性。对于某些已经从Control基类被移除的属性(例如visible),您能够通过子属性来访问到它们。下面的示例展示了如何设定一个Button元素的style属性。 <script type="text/xml-script"> <page xmlns:script="http://schemas.microsoft.com/xml-script/2005" xmlns:"JavaScript: Sys.UI, Sys"> <components> <textbox id="Name" /> <label id="FirstName"> <bindings> <binding dataContext="Name" dataPath="text" property="text"/> </bindings> </label> <button id="button2"> <click> <setPropertyAction target="text1" property="element" propertyKey="style.borderColor" value="black" /> </click> </button> </components> </page> </script> 这个示例也展示了action的使用方式:setPropertyAction在Button控件的click事件触发时被调用。 References 在CTP版本中您能够在XML-Script添加对于脚本的引用,在Value-add Beta版本中并没有支持这个功能。RTM版本很可能会解决这个问题。 本文出自 “赵劼” 博客,转载请与作者联系! 本文出自 51CTO.COM技术博客 |



jeffz
博客统计信息
热门文章
最新评论
友情链接
