我有一个ContentPlaceHolder的标准母版页。。用户控件中的.net窗体在回发后丢失值
<section class="content" style="height:100%;">
<form id="contentForm" runat="server">
<div class="container" style="background:#fff; border:30px solid #fff; height:80%;">
<div class="row" style="height:100%;">
<section class="span8" role="main" style="height:100%;">
<asp:ContentPlaceHolder Id="MainContent" runat="server" />
</section>
</div>
</div>
</form>
</section>
Inside ContentPlaceHolder我有一个包含下拉列表和文本框的用户控件。
使用母版页中的from标签,如果更改下拉选择,页面将按预期方式提交,并且表单字段将保留其选定值。现在,我需要从母版页中删除标签,因为它会导致其他页面失败。我想把表单标签放在usercontrol里面。
<form id="trackingForm" runat="server">
<div id="employee" class="statsTable"><strong>Employee:</strong>
<asp:DropDownList ID="selectPerson_DDL" runat="server" Width="200" AutoPostBack="true" onselectedindexchanged="selectPerson_DDL_SelectedIndexChanged"></asp:DropDownList>
</div>
</form>
页面仍然像以前一样提交,但现在我在下拉列表中丢失了选定的值。我已经尝试过各种选项,比如检查Page.IsPostBack等等。我在提交表单后发现ViewState存在。
为什么控件行为只是因为form标签现在在usercontrol中而改变?
您可以使用更新面板来避免回发 – 2014-11-03 16:47:29
我使用完整页面回发进行,因为页面上有几个控件基于该下拉选项进行填充。当时看起来比较容易。现在,我可能会后悔。 – 2014-11-03 16:55:16
ASP.NET WebForms仅支持每页具有runat =“server”的FORM元素。是否有一个原因,你必须使用FORM,你是否不能用DIV替换它? – sh1rts 2014-11-03 23:42:50