如何分别在母版页和内容页中使用Ajax ScriptManager和ToolkitScriptManager,而不会出现错误 [英] 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解决此问题,因为我认为这是解决此问题的更好方法?
这是我的母版页代码:
I have an Ajax Script manager in my Master page since my pages use ajax. But in one of my content pages, I need to use AutoCompleteExtender in AjaxControlToolkit which requires the use of ToolScriptManager available in the toolkit. But this leads to an error saying Only one instance of a ScriptManager can be added to the page. I searched over the internet for a solution. Many programmers suggests the use of a ScriptManagerProxy to solve this issue. Another alternative is using ToolscriptManager in the master page instead of ScriptManager. Can anyone please demonstrate how to solve this issue by using ScriptManagerProxy since I think that is a better way of solving the issue?
Here is the code of my master page:
<form runat="server" id="bodyForm">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:ContentPlaceHolder ID="ContentPlaceHolderBodyMain" runat="server">
</asp:ContentPlaceHolder>
</form>
这是我的内容页面的代码:
And here is the code of my content page:
<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>
推荐答案
find('AutoCompleteEx'); 如果(!behavior._height){ var target = behavior.get_completionList(); behavior._height = target.offsetHeight-2; target.style.height ='0px'; }" / <%- 在 -%> < 并行 =" .2" < 淡入 > < 长度 =" height" StartValue 0" span> EndValueScript ="
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 > < /序列 > < /OnShow > < OnHide > <%- 折叠至0px并淡出 < 并行 =" .2" < FadeOut > < 长度 =" height" StartValueScript
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 =" / >> < /Parallel > < /OnHide > < /动画 > < /asp:AutoCompleteExtender >
find('AutoCompleteEx')._height" EndValue="0" /> </Parallel> </OnHide> </Animations> </asp:AutoCompleteExtender>
这篇关于如何分别在母版页和内容页中使用Ajax ScriptManager和ToolkitScriptManager,而不会出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!