Hidden Field losing its Value on postback
Posted
by Ratan
on Stack Overflow
See other posts from Stack Overflow
or by Ratan
Published on 2010-06-07T19:57:26Z
Indexed on
2010/06/07
20:02 UTC
Read the original article
Hit count: 783
I have a ascx page where I am using a hidden field to store the value of a the drop down box as it is generated using a google address finder. My problem is that when I try to store the value directly in the hidden field :
hfDdlVerifyID.Value = ddlVerifySS.SelectedValue;
in the event of a button click, the value is stored but on postback is lost again. Whereas, if i try to use Scriptmanager to do it, nothing is stored.
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();
The ascx page is :
<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" />
© Stack Overflow or respective owner