Hidden Field Value_Changed Event Not Firing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • femina
    New Member
    • Dec 2007
    • 35

    Hidden Field Value_Changed Event Not Firing

    the ValueHiddenFiel d_ValueChanged event is not firing
    please help me how to trigger my value changed event so that Message.Text that is "The value of the HiddenField control is " + ValueHiddenFiel d.Value
    is displayed in my web page

    Code:
    <script runat="server">
    void ValueHiddenField_ValueChanged (Object sender, EventArgs e)
      {
    
        // Display the value of the HiddenField control.
        Message.Text = "The value of the HiddenField control is " + ValueHiddenField.Value + ".";
    
      }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
         <h3>HiddenField Example</h3>
    
                Please enter a value and click the submit button.<br/>
    
                <asp:Textbox id="ValueTextBox"
                  runat="server"/>
    
                <br/>  
    
                <input type="submit" name="SubmitButton"
                 value="Submit"
                 onclick="PageLoad()" />
    
                <br/>
    
                <asp:label id="Message" runat="server"/>&nbsp;
    
        </div>
    
                <asp:hiddenfield id="ValueHiddenField"
                  onvaluechanged="ValueHiddenField_ValueChanged"
                  value="" 
                  runat="server"/>
        </form>
    </body>
    </html>
    
    <script type="text/javascript">
      <!--
      function PageLoad()
      {
        // Set the value of the HiddenField control with the
        // value from the TextBox.
        Form1.ValueHiddenField.value = Form1.ValueTextBox.value;
    
      }
      -->
    </script>
    Last edited by femina; Aug 22 '08, 01:35 PM. Reason: proper title
  • cloud255
    Recognized Expert Contributor
    • Jun 2008
    • 427

    #2
    Well, according to the MSDN, the event is only raised if the value changes between postbacks...

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Yes, the events only occur durring a postback.
      Also, if it's a hidden field, how is it being changed?

      Comment

      • femina
        New Member
        • Dec 2007
        • 35

        #4
        so if the Value_Changed event triggers between post backs
        lets assume textbox value is "femina" for the first time i click a button and if i change my text box value the next time say "fayaz" and then i click my button.
        Now will the Value_Changed event be triggered since i have assigned my hiddenfield value with the textbox value each time before submitting the button
        Code:
        void ValueHiddenField_ValueChanged (Object sender, EventArgs e)
          {
        
            // Display the value of the HiddenField control.
           Label1.Text += "The value of the HiddenField control is " + HiddenField1.Value + ".";
          }
        so will the label text be modified in the web page
        please clear my doubts

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Changing the value in code behind would not trigger the Value_changed event. However, since you're already IN the code at that point, why not just call the function from code anyway?

          Comment

          Working...