我有一个ascx页面,我在其中使用一个隐藏字段来存储下拉框的值,因为它是使用Google地址查找器生成的。我的问题是,当我尝试将值直接存储在隐藏字段中时:
hfDdlVerifyID.Value = ddlVerifySS.SelectedValue;
如果单击按钮,则会存储该值,但在回发时会再次丢失。而如果我尝试使用Scriptmanager进行操作,则不会存储任何内容。
getBuild.AppendLine("$get('" + hfDdlVerifyID.ClientID + "').value = $get('" + ddlVerifySS.ClientID + ").value;");
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "storeHidden", getBuild.ToString(), true);
// Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "storeHidden", getBuild.ToString(), true);
string test = hfDdlVerifyID.Value.ToString();
ascx页面是:
<asp:UpdatePanel ID = ddlUpdate runat="server">
<ContentTemplate>
<asp:Panel ID="pVerify" runat="server">
<br />
<fieldset>
<legend>
<asp:Literal ID="lVerify" runat="server" />
</legend>
<asp:CheckBox
ID ="cbVerify"
runat ="server"
Text ="Use the value from the following list, (Uncheck to accept address as it is)."
Checked ="true" />
<br />
<asp:DropDownList ID="ddlVerifySS" runat="server"
onselectedindexchanged="ddlVerifySS_SelectIndexChange" />
<asp:HiddenField id="hfDdlVerifyID"
runat ="server" />
</fieldset>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<padrap:Button ID ="bVerify"
runat ="server"
CssClass ="btn"
OnClick ="bVerify_Click"
Text ="Verify Address" />
<asp:Button ID ="btnSubSite"
runat ="server"
text ="Save"
CssCLass ="btn"
OnClick ="save_btn_Click_subSite"
onLoad="ddlVerify_Load" />
最佳答案
您应该考虑使用Viewstate。
希望这可以帮助
http://msdn.microsoft.com/en-us/library/bb386448.aspx#Y2000
关于jquery - 隐藏字段在回发时失去其值(value),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2992670/