[英]How to use AJAX in master page when content pages have ScriptManager?
[英]How to use Ajax ScriptManager and ToolkitScriptManager in master page and content pages respectively without errors
我的主頁面中有一個Ajax腳本管理器,因為我的頁面使用了ajax。 但是在我的一個內容頁面中,我需要在AjaxControlToolkit中使用AutoCompleteExtender,它需要使用工具包中提供的ToolScriptManager。 但是這會導致錯誤, 只能將一個ScriptManager實例添加到頁面中 。 我在互聯網上搜索了一個解決方案。 許多程序員建議使用ScriptManagerProxy來解決這個問題。 另一種方法是在母版頁中使用ToolscriptManager而不是ScriptManager。 任何人都可以通過使用ScriptManagerProxy來演示如何解決這個問題,因為我認為這是解決問題的更好方法嗎?
這是我的母版頁的代碼:
<form runat="server" id="bodyForm">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:ContentPlaceHolder ID="ContentPlaceHolderBodyMain" runat="server">
</asp:ContentPlaceHolder>
</form>
這是我的內容頁面的代碼:
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:TextBox ID="TextBoxStudentID" runat="server" autocomplete="off"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtenderStudentID" runat="server"
EnableCaching="true" BehaviorID="AutoCompleteEx" MinimumPrefixLength="2"
TargetControlID="TextBoxStudentID" ServicePath="~/CampusMateWebService.asmx" ServiceMethod="GetCompletionListForStudentID"
CompletionInterval="50" CompletionSetCount="30"
CompletionListCssClass="autocomplete_completionListElement" CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :" ShowOnlyCurrentWordInCompletionListItem="true">
<Animations>
<OnShow>
<Sequence>
<%-- Make the completion list transparent and then show it --%>
<OpacityAction Opacity="0" />
<HideAction Visible="true" />
<%--Cache the original size of the completion list the first time
the animation is played and then set it to zero --%>
<ScriptAction Script="// Cache the size and setup the initial size
var behavior = $find('AutoCompleteEx');
if (!behavior._height) {
var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2;
target.style.height = '0px';
}" />
<%-- Expand from 0px to the appropriate size while fading in --%>
<Parallel Duration=".2">
<FadeIn />
<Length PropertyKey="height" StartValue="0"
EndValueScript="$find('AutoCompleteEx')._height" />
</Parallel>
</Sequence>
</OnShow>
<OnHide>
<%-- Collapse down to 0px and fade out --%>
<Parallel Duration=".2">
<FadeOut />
<Length PropertyKey="height" StartValueScript=
"$find('AutoCompleteEx')._height" EndValue="0" />
</Parallel>
</OnHide>
</Animations>
</asp:AutoCompleteExtender>
從舊版本的AjaxControlToolkit更新(並從.NET 2.0升級到3.5)時,我遇到了類似的問題。
另一種方法是在母版頁中使用ToolscriptManager而不是ScriptManager。 任何人都可以通過使用ScriptManagerProxy來演示如何解決這個問題,因為我認為這是解決問題的更好方法嗎?
我不明白為什么那會是更好的方式。 然后,您需要在每個子頁面上放置一個ScriptManager。 在Master頁面上用ToolkitScriptManager替換ScriptManager並完成它有什么問題?
這可以在http://www.asp.net/ajaxlibrary/act_faq.ashx上找到 :
- ScriptManager控件和ToolkitScriptManager控件之間有什么區別? 我們建議您在使用Ajax Control Toolkit時使用ToolkitScriptManager控件。 ToolkitScriptManager使用比ScriptManager控件更高版本的ASP.NET Ajax。 此外,ToolkitScriptManager在服務器上執行自動腳本組合。 在ASP.NET 3.5中使用Ajax Control Toolkit時,您需要使用ToolkitScriptManager
ScriptManagerProxy允許內容頁面傳遞對母版頁中放置的ScriptManager的引用。
ScriptManagerProxy控件使用戶能夠添加特定於嵌套組件的腳本和服務。 如果頁面已包含ScriptManager控件。 只能將一個ScriptManager控件實例添加到頁面中。 頁面可以直接或間接地在嵌套組件(例如用戶控件或嵌套母版頁)內包含控件。 當ScriptManager控件已經在頁面中並且嵌套或父組件需要ScriptManager控件的其他功能時,將使用ScriptManagerProxy控件。
你只需在body asp或ContentPlaceHolder中添加: <asp:ScriptManager ID="ScriptManager1" runat="server" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.