母版页中的脚本管理器和用户控件中的更新面板。 部分回发未发生
我有一个带有以下 scriptmanager 标签的母版页:
<asp:ScriptManager ID="scriptManger" EnablePartialRendering="true" runat="server" >
<Scripts>
<asp:ScriptReference Path="~/common/js/jquery-1.3.2.js" />
<asp:ScriptReference Path="~/common/js/validation.js" />
</Scripts>
</asp:ScriptManager>
我的 aspx 页面是:
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/common/MasterPages/Login.master" CodeBehind="SecurityQuestionsEnroll.aspx.cs" Inherits="Login.SecurityQuestionsEnroll" %>
<%@ Register src="~/controls/Views/Login/SecurityQuestions.ascx" tagname="SecurityQuestions" tagprefix="uc1" %>
这是用户控件:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="always" >
<ContentTemplate>
<asp:DataList ID="dlSecurityQuestions" runat="server" AutoPostBack="true" OnSelectedIndexChanged ="dlSecurityQuestions_SelectedIndexChanged">
<ItemTemplate>
<div>
<asp:Label ID="lbl_question" AssociatedControlID="lst_question" runat="server"><%# DataBinder.Eval(Container.DataItem, "QuestionName")%></asp:Label>
<asp:DropDownList ID="lst_question" runat="server" AutoPostBack="true" >
<asp:ListItem Value="0">Select a Question...</asp:ListItem>
<asp:ListItem Value="1">Select a Question1..</asp:ListItem>
</asp:DropDownList>
</div>
<div>
<asp:Label ID="lbl_answer1" AssociatedControlID="txt_answer" runat="server">Answer *</asp:Label>
<asp:TextBox ID="txt_answer" runat="server" />
<div id="validate"></div>
</div>
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
我已经尝试了谷歌推荐的大部分选项,但我无法进行部分回发。 每次选定索引更改时,它都会进行整页回发。 正如您所看到的,下拉菜单位于项目模板中并且是重复的。 您认为我做错了什么,它不触发更新面板的回发。
i have a master page with following scriptmanager tag:
<asp:ScriptManager ID="scriptManger" EnablePartialRendering="true" runat="server" >
<Scripts>
<asp:ScriptReference Path="~/common/js/jquery-1.3.2.js" />
<asp:ScriptReference Path="~/common/js/validation.js" />
</Scripts>
</asp:ScriptManager>
My aspx page is :
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/common/MasterPages/Login.master" CodeBehind="SecurityQuestionsEnroll.aspx.cs" Inherits="Login.SecurityQuestionsEnroll" %>
<%@ Register src="~/controls/Views/Login/SecurityQuestions.ascx" tagname="SecurityQuestions" tagprefix="uc1" %>
and this is the user control:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="always" >
<ContentTemplate>
<asp:DataList ID="dlSecurityQuestions" runat="server" AutoPostBack="true" OnSelectedIndexChanged ="dlSecurityQuestions_SelectedIndexChanged">
<ItemTemplate>
<div>
<asp:Label ID="lbl_question" AssociatedControlID="lst_question" runat="server"><%# DataBinder.Eval(Container.DataItem, "QuestionName")%></asp:Label>
<asp:DropDownList ID="lst_question" runat="server" AutoPostBack="true" >
<asp:ListItem Value="0">Select a Question...</asp:ListItem>
<asp:ListItem Value="1">Select a Question1..</asp:ListItem>
</asp:DropDownList>
</div>
<div>
<asp:Label ID="lbl_answer1" AssociatedControlID="txt_answer" runat="server">Answer *</asp:Label>
<asp:TextBox ID="txt_answer" runat="server" />
<div id="validate"></div>
</div>
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
I have tried most of the options which google recommends, but i am not able to do a partial postback. evry time selectedindex is changed it does a full page postback. the drop down as you can see is in a itemtemplate and is repeated.
what do you think I am doing wrong that its not firing postback of just the update panel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您有更新面板但没有脚本管理器,则此方法有效:
但我也有一个母版页。 所以我想知道是不是因为母版页我需要脚本管理器
This works if you have an update Panel but no Script Manager:
But I also have a master page. So I wonder is it because of the Master page that I require the Script Manager
我构建了一个小测试项目来稍微模仿您的文件。 我没有使用 DataList,并且我已将需要更新的区域移至单独的 div 中(这意味着如果您保留 DataList,我认为您的问题/答案不会像您那样位于 DataList 内现在,我构建的示例只是从下拉列表中获取文本,并使用用户选择的选项更新 UpdatePanel 中的文字,
这是我的代码:
MasterPage:
默认页面(代码中没有其他代码) 。后面):
用户控制(Html):
用户控制(代码隐藏):
I built a little test project that mimics your files a little bit. I'm not using a DataList and I've moved the area that needs to be updated into a seperate div (meaning that if you keep the DataList, I don't think your question/answer would be located inside the DataList the way you have it now. So right now, the sample I built just grabs the text from a drop down list and updates a literal in the UpdatePanel with the option the user selected.
Here's my code:
MasterPage:
Default page (no additional code in code-behind):
User Control (Html):
User Control (Code-behind):
我在
UpdatePanel
定义中看到
- 这需要如果您希望 UpdatePanel 异步工作,则为UpdateMode="Conditional"
。 不知道为什么 ASP:NET 开发人员一开始没有将其设置为默认条件(我有时仍然忘记它)。也许已经是这样了?
I see
<asp:UpdatePanel ID="id" runat="server" ChildrenAsTriggers="true" UpdateMode="always" >
in yourUpdatePanel
definition - this needs to beUpdateMode="Conditional"
if you want your UpdatePanel to work asynchronously. No idea why the ASP:NET devs didn't set it to Conditional as a default in the first place (I still sometimes forget it).Maybe that's already it?