Community discussion forum

losing Javasript values on postback

  • 2 years ago

    Okay, I know this is probably b/c of my javascript ignorance, but @ postback, I lose my javascript created values. I'm assuming it's b/c the view state isn't updated, so when the page posts back, the textbox values just go back to what's set in the "Text" property at design time...which is 0.

    Do I have to register the client script or something?

    I'm trying to do an onblur to have two textboxes the same and a simple division with two fields/textboxes to update a third textbox to save server posts.

     Any help/ideas are appreciated!

  • 2 years ago
    All these textboxes are asp.net textboxes, and "Enable View State" is true. For my onblur situation, I can use the OnTextChanged in codebehind, but that's a little slow, but if I change it to the javascript it's almost instant, but postback makes the target textbox value back to 0. When I try my button click to do a division, it works, but on postback, the value is back to 0. I can use codebehind, but it's a little slower. I am using an AJAX tabs control with update panels...don't know if that's really an issue there.
  • 2 years ago

    I'm trying to do two things with javascript to avoid postbacks:

    1. populate a "ReadOnly" text box with another textbox's value onblur (OnTextChanged with codebehind) so that two are in synch, and the "driver" textbox is the "control value" for the read-only textbox.

    2. On a buttom click, I'm trying to calculate a decimal value based off two textbox values.

    I've tried to use the ASP.NET image button's "OnClientClick", and that didn't help either.

    So, even though the values are in an ASP:TextBox, and EnableViewState is set to True, I'll still need to use Hidden fields?

    What's interesting is that in my javascript function, I had to use the following full name for the textboxes since they were in an AJAX tab control: function Synch() { var x=document.getElementById("TabContainer1_TabPanel3_txtParent").value; document.getElementById("TabContainer1_TabPanel3_txtChild").value=x; }

    <script type="text/javascript">
            function Synch()
            {
                var x=document.getElementById("TabContainer1_TabPanel3_txtParent").value;
                document.getElementById("TabContainer1_TabPanel3_txtChild").value=x;
            }

  • 2 years ago

    Found this, and it's keeping my onblur values now:

    http://geekswithblogs.net/ranganh/archive/2007/05/10/112390.aspx

  • 1 year ago

    Tank you man !! it worked ! Big Smile

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback