控制 SelectedIndexChanged 上 UpdatePanel 的可见性
经过几个小时的调试这个问题(见标题)后,我求助于互联网。提前声明,是的,我在创建这个问题时已经阅读了“具有类似标题的问题”。虽然他们确实提供了一些很好的见解,但尚未达成解决方案。
这是基本的事件映射:
- 页面加载,RadioListBox 的第一个索引[0] 设置为 selected="true"。
- 用户选择其他索引,如果选择特定项目值,则设置 后续面板的“真实”可见性
我对 ASP.NET AJAX 世界相当陌生,因此非常感谢任何和所有建议。除非你告诉我吃便便,否则我可能不会感激。
这是代码,后面是我调试它所采取的步骤。
标记:(是的,我知道不在表单标签内的字段集不是语义的,我稍后会担心这一点)
<asp:UpdatePanel runat="server" ID="updpnlDDCancelPartnerOpts" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel runat="server" CssClass="frmDDCancelPartnerOpts">
<fieldset>
<legend>Digital Cancellation Options:</legend>
<br />
<asp:RadioButtonList ID="rdlstCancellOptions" runat="server" AutoPostBack="true"
cssclass="rdBtnLstDDCancelOpts" onselectedindexchanged="rdlstCancellOptions_SelectedIndexChanged">
<asp:ListItem Value="cancelall" Selected="True">Cancel ALL Digital Distribution:</asp:ListItem>
<asp:ListItem Value="canceldotcom">Cancel CD Baby ONLY:</asp:ListItem>
<asp:ListItem Value="partnercancellations">Cancel From Specific Partners:</asp:ListItem>
</asp:RadioButtonList>
</fieldset>
</asp:Panel>
<asp:Panel runat="server" ID="pnlChecks" CssClass="partner">
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rdlstCancellOptions" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
代码隐藏:(我只是发布事件方法,如果您想查看更多内容,请询问:)
protected void rdlstCancellOptions_SelectedIndexChanged(object sender, EventArgs e)
{
if (rdlstCancellOptions.SelectedValue == "partnercancellations")
{
pnlChecks.Visible = true;
updpnlDDCancelPartnerOpts.Update();
}
}
调试:
我已将每个(RLB 控件和 pnlChecks 面板)包装在单独的 UpdatePanel 中,我使用了触发器,但没有使用它们,几乎使用了 AutoPostBack 的所有组合。
最重要的是,当在事件函数上设置断点时,它会命中断点,迭代它,然后返回到页面 - 无需刷新并将 pnlChecks 面板设置为可见。
ScriptManager 包含在 MasterPage 中。
我知道我可能遗漏了大量信息。然而,已经很晚了,在一天工作了 17 个小时之后(不,不是所有的 17 个小时都花在这上面了),我不能再强迫我的眼睛盯着电脑屏幕了。
所以,如果我遗漏了什么(很可能是显而易见的),请随时分享。 +万互联网给所有人!
库霍伊0x
After several hours of debugging this issue (see title) I am resorting to the internets. To state in advance, yes I have read the "Questions with similar titles" whilst creating this question. While they did provide some good insight, a solution has not been reached.
Here is the basic event map:
- Page loads, RadioListBox's first index[0] is set to selected="true".
- User selects other index, if a particular item value is chosen, set
visibility to "true" of subsequent Panel
I am fairly new to the ASP.NET AJAX world, so any and all advice is appreciated. Unless you tell me to eat poo, I might not appreciate that.
Here is the code followed by steps I have taken to debug it.
Markup: (yes I know fieldsets not inside of form tags isn't semantic, I'll worry about that later)
<asp:UpdatePanel runat="server" ID="updpnlDDCancelPartnerOpts" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel runat="server" CssClass="frmDDCancelPartnerOpts">
<fieldset>
<legend>Digital Cancellation Options:</legend>
<br />
<asp:RadioButtonList ID="rdlstCancellOptions" runat="server" AutoPostBack="true"
cssclass="rdBtnLstDDCancelOpts" onselectedindexchanged="rdlstCancellOptions_SelectedIndexChanged">
<asp:ListItem Value="cancelall" Selected="True">Cancel ALL Digital Distribution:</asp:ListItem>
<asp:ListItem Value="canceldotcom">Cancel CD Baby ONLY:</asp:ListItem>
<asp:ListItem Value="partnercancellations">Cancel From Specific Partners:</asp:ListItem>
</asp:RadioButtonList>
</fieldset>
</asp:Panel>
<asp:Panel runat="server" ID="pnlChecks" CssClass="partner">
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="rdlstCancellOptions" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
CodeBehind: (I'm just posting the Event method, if you wish to see more, just ask :)
protected void rdlstCancellOptions_SelectedIndexChanged(object sender, EventArgs e)
{
if (rdlstCancellOptions.SelectedValue == "partnercancellations")
{
pnlChecks.Visible = true;
updpnlDDCancelPartnerOpts.Update();
}
}
Debuggin':
I have wrapped each ( the RLB control and the pnlChecks panel) in separate UpdatePanels, I have used triggers and not used them, with just about every combination of AutoPostBack.
Most of all though, when A break point is set on the event function, it hits it, iterates through it and then returns you to the page - without refreshing and setting the pnlChecks Panel to visible.
The ScriptManager is included in the MasterPage.
I know I'm probably leaving out hordes of information. It is late, however, and after a 17 hours work day ( no not all 17 hours was spent on this) I can no longer force my eyes to stare at a computer screen.
So please, if there is anything ( most likely obvious) that I am missing, feel free to share. +million internet to all!
Koohoy0x
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
你的代码没问题,但面板没有什么可显示的,它已经可见了:)
Try this:
Your code is OK but the panel got nothing to show, it's already visible :)
找到答案了。用于填充数据源的参数是不同方法的本地参数,因此向复选框列表返回 null。使用 Count 进行调试,我们发现数据甚至没有生成。不过,Ajax 运行良好。感谢大家的回复和时间。
Answer found. The parameter used to populate the datasource was local to a different method, thus returning null to the checkbox list. Debbuging using Count we figured out that the data wasn't even being generated. The Ajax is working fine, however. Thank you all for your response and time.