这是我的问题:
但是当我尝试在btnSubmit_Click()中获取 ddlType.SelectedValue 时,它总是返回“选择一个类型”。
如果我不做第2步,那么它可以正常工作。 根据我的理解,问题与ajax调用(回发)有关,可以通过在Session或ViewState中保存SelectedValue来解决。
但是我在这个页面上有很多其他控件(例如ddlType),所以它看起来不是一个优雅的解决方案。我希望框架能够自动将所选值保存在ViewState中......任何想法?毕竟,UpdatePanel的目标不仅仅是更新面板吗?
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:DropDownList ID="ddlType" runat="server">
<asp:ListItem Text="Select a type" Value=""></asp:ListItem>
<asp:ListItem Text="One" Value="1"></asp:ListItem>
<asp:ListItem Text="Two" Value="2"></asp:ListItem>
<asp:ListItem Text="Three" Value="3"></asp:ListItem>
</asp:DropDownList>
<div>
<strong>Choices</strong>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAddChoice" EventName="Click" />
</Triggers>
<ContentTemplate>
<ul class="list-unstyled">
<asp:PlaceHolder runat="server" ID="phChoices"></asp:PlaceHolder>
</ul>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="btnAddChoice" runat="server" Text="Add Choice" CausesValidation="false"
OnClick="btnAddChoice_Click" />
</div>
<asp:Button ID="btnSubmit" runat="server" Text="Add question"
OnClick="btnSubmit_Click" />
更新
问题的部分原因是:
$('#<%= MainPanel.FindControl("btnAddChoice").ClientID %>').click(function () {
var ddlType = $('#<%= MainPanel.FindControl("ddlType").ClientID %>');
ddlType.attr('disabled', 'disabled');
});
有关详细信息,请参阅此question。 关于其他控件也是空的,原因是"dynamically created controls have to be created each and every post-back"
答案 0 :(得分:0)
尝试在ScriptManager
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
然后,您想要刷新的所有代码都将归入Update Panel
<asp:Updatepanel id="UpdatePanel1" runat="server">
<ContentTemplate>
...All your HTML content here
</ContentTemplate>
</asp:Updatepanel>
&#13;
希望有所帮助
的更多信息<强>更新强>
此外,如果由于dropdownlist
Updatepanel
值
尝试Request.Form
并检查
Request.Form.Get("dropdownlistID").ToString());