ASP.NET AJAX中ScriptManager控件
在ASP.NET AJAX中,由于一個ASPX頁面上只能有一個ScriptManager控件,所以在有Master-Page的情況下,如果需要在Master-Page和Content-Page中需要引入不同的腳本時,就需要在Content-page中使用ScriptManagerProxy控件,而不是ScriptManager,ScriptManagerProxy和 ScriptManager是兩個非常相似的控件。ASP.NET AJAX簡單定義形式如下:
- <asp:ScriptManagerProxyidasp:ScriptManagerProxyid="ScriptManagerProxy1"runat="server">
- <Services>
- <asp:ServiceReferencePathasp:ServiceReferencePath="CalculWebService.asmx"/>
- </Services>
- </asp:ScriptManagerProxy>
在它下面可以添加的子標簽有:Services,Scripts,AuthenticationService,ProfileService
添加一個Master-Page,在它上面添加一個ScriptManager控件,并引入WebService SimpleWebService.asmx,并添加相應(yīng)的HTML元素:
- <div>
- <asp:ScriptManagerIDasp:ScriptManagerID="ScriptManager1"runat="server">
- <Services>
- <asp:ServiceReferencePathasp:ServiceReferencePath=
"SimpleWebService.asmx"/>- </Services>
- </asp:ScriptManager>
- <asp:contentplaceholderidasp:contentplaceholderid=
"ContentPlaceHolder1"runat="server">- </asp:contentplaceholder>
- <h3>請輸入名稱:</h3>
- <inputidinputid="inputName"type="text"/>
- <inputidinputid="button"type="button"value="確定"onclick=
"returnOnbuttonGo_click()"/>- </div>
添加一個Content-Page,在它上面添加一個ScriptManagerProxy控件,并引入WebService CalculWebService.asmx,并添加相應(yīng)的HTML元素:
- <div>
- <asp:ScriptManagerProxyidasp:ScriptManagerProxyid=
"ScriptManagerProxy1"runat="server">- <Services>
- <asp:ServiceReferencePathasp:ServiceReferencePath=
"CalculWebService.asmx"/>- </Services>
- </asp:ScriptManagerProxy>
- <h3>請輸入兩個數(shù):</h3> <inputidinputid="inputA"type=
"text"style="width:110px"/> + - <inputidinputid="inputB"style="width:110px"type="text"/>
- <inputidinputid="buttonEqual"type="button"value="="onclick=
"returnOnbuttonEqual_click()"/>- </div>
關(guān)于ASP.NET AJAX中ScriptManagerProxy控件就介紹到這兒,有個問題就是在我的IDE中為什么ScriptManagerProxy總是提示為未知元素,但運行起來并不抱錯,結(jié)果也可以出來?
【編輯推薦】