Link to home
Start Free TrialLog in
Avatar of ameert
ameert

asked on

ValueChanged event for HiddenField not firing for some reason.

I have an aspx page with a label and a hidden field. Through javascript, I set the value of the hidden field, and then call __doPostBack. But the valuechanged event doesn't fire. Is this correct what I have below (I believe it is). My aspx page has a master page and everything within my aspx paage is all inside content tags.

<script language=javascript>
            function ConfigureDialog()
            {
                var ea = "<%= Request.Form["__EVENTARGUMENT"]  %>";
                if (ea != "HdnFldSet")
                {
                      var ttt = "val1";
                      var oRouteType = document.getElementById("<%= HiddenField6.ClientID %>");
                      oRouteType.Value = ttt;
                          __doPostBack("HiddenField6",'HdnFldSet'); //i even tried "<%= HiddenField6.ClientID %>" in place of "HiddenField6" here
                     }
              }
</script>
    <asp:HiddenField ID="HiddenField6" runat="server" OnValueChanged="HiddenField6_ValueChanged" />

     <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></p>
<script>
     ConfigureDialog();
</script>


Then on code behind page:

        protected void HiddenField6_ValueChanged(object sender, EventArgs e)
        {
            Label1.Text = "someText...never shows for some reason.";
        }

By the way I have page EnableEventValidation set to false. I open this page as a popup from another page.
Please tell me if there is anything wrong with this code....the valueChanged event never fires and I can't understand why.
Avatar of Emad Gawai
Emad Gawai
Flag of United Arab Emirates image

what if you change protected to public ?

public void HiddenField6_ValueChanged(object sender, EventArgs e)
        {
            Label1.Text = "someText...never shows for some reason.";
        }
or sure javascript instead

<script lanugage=javascript runat=server>

function onHiddenFieldchange(){
 document.getElementById("Label1").value = "changed text shown";
}

</script>

Avatar of ameert
ameert

ASKER

Hello gawai, no luck with that either.

Strange this this works fine from a parent window....but then in the popup window it's not working and it's the exact same code.
Avatar of ameert

ASKER

i can't use the second option because in the c# event I have, I need to set some properties to a datagrid depending on what value was assigned to the hiddenfield
might you have missed some lines of code in popup window page.
Avatar of ameert

ASKER

Does anyone have a solution to this? I really need to get this done.
Avatar of ameert

ASKER

Ok, figured it out.....I'm posting this soln in case anyone else has a similar problem.

I added the following to Render event and I turned on EnableEventValidation:

Page.ClientScript.RegisterForEventValidation(this.HiddenField6.UniqueID, "");

I also changed <%= HiddenField6.ClientID %> to <%= HiddenField6.UniqueID %>
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial