views:

201

answers:

1

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" />
A: 

Does your this code work if you remove the UpdatePanel?

Also, the code you posted for the getBuild call is missing a closing single quote in the call to $get for the item ddlVerifySS.ClientID. Is this a typo entering this here, or a problem in your code? If it is the latter, this would explain why you don't see the value copied when you use the script manager.

Steven Raines