DropDownList的SelectedValue的disapperaing上提交(未发行的IsPostBack!) [英] dropdownlist selectedvalue disapperaing on Submit (not IsPostBack issue!)
问题描述
我有状态的一个DropDownList当页面最初被加载(ddl_state)得到填充。我选择一个状态,然后点击提交按钮。我对btn_submit_Click方法的第一行一个断点。在Page_Load方法没有得到在此之前运行。在btn_submit_Click方法的第一行,ddl_state.SelectedValue的值是空字符串。我尝试设置的AutoPostBack将DropDownList为true(读这地方,并认为这可能有所作为),但随后在DropDownList的值只得到立即清除!
任何想法?
< ASP:DropDownList的ID =ddl_state=服务器
元:获取ResourceKey =ddl_stateResource1>
< / ASP:DropDownList的>保护无效的Page_Load(对象发件人,EventArgs的发送)
{
如果(的IsPostBack)回报; lbl_errors.Text =的String.Empty;
lblVoucherRequired.Text =的String.Empty; tb_name_addr_1.Focus();
PopulateStates();
PopulateFormFromSessionData();
}保护无效btn_submit_Click(对象发件人,EventArgs的发送)
{
如果(!ValidateInput())// ddl_state.SelectedValue这里是一个空字符串!
{
返回;
} SetSessionVariables();
您的问题是,的ViewState
是禁用的。
这表明您的两个症状:
-
的DropDownList
与回传的AutoPostBack
已启用 之后清除 - 服务器不知道是什么
的SelectedValue
的的DropDownList
是
检查web.config,页面和控件来检查,没有张师傅禁用ViewState中。
I have a DropDownList of states getting populated when the page initially gets loaded (ddl_state). I select a state, then click the Submit button. I have a breakpoint on the first line of the btn_submit_Click method. The Page_Load method is not getting run prior to this. On the first line of the btn_submit_Click method, the value of ddl_state.SelectedValue is an empty string. I tried setting AutoPostBack of the dropdownlist to true (read this somewhere and thought it might make a difference), but then the values in the dropdownlist just get cleared immediately!
Any ideas?
<asp:DropDownList ID="ddl_state" runat="server"
meta:resourcekey="ddl_stateResource1">
</asp:DropDownList>
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
lbl_errors.Text = string.Empty;
lblVoucherRequired.Text = string.Empty;
tb_name_addr_1.Focus();
PopulateStates();
PopulateFormFromSessionData();
}
protected void btn_submit_Click(object sender, EventArgs e)
{
if (!ValidateInput()) // ddl_state.SelectedValue is an empty string here!!!
{
return;
}
SetSessionVariables();
Your issue is that ViewState
is disabled.
This is indicative of both of your symptoms:
DropDownList
clears after postback withAutoPostBack
is enabled- Server does not know what the
SelectedValue
of theDropDownList
is
Check the web.config, page, and control to check that none of them are disabling viewstate.
这篇关于DropDownList的SelectedValue的disapperaing上提交(未发行的IsPostBack!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!