I have a bit of javasript that writes a value to a text box. The text box is read only.
Textbox code:
<input type="text" id="txtColor1" runat="server" readonly="readonly" size="6" />Snippet from javascript function
colorBox = document.getElementById('<%= txtColor1.ClientID %>');
colorBox.value = colorCode;Code behind:
string color1 = txtColor1.ValueWhenever I attempt to get the value out of the text box after it has been changed by the javascript, it always reverts back to the old data and not the new.
Anyone have an idea of what may be causing this?
thanks ^.^
![]() |
-1 |
![]() |
It's an issue with order of operations between when your javascript fires and when the page does a postback. Can you lay out the sequence of events for when/how your javascript gets fired and what triggers your postback?
Thanks,
![]() |
1 |
![]() |
I'll give it a shot of what I believe it does in the order of operation:
1. Page loads and fills in the information
2. I use the javascript to fill in the new values after selecting a new choice. Setting the new value seems to works just fine as the value is put into the box.
3. Click the save button (.net button) to save the changes. This does the post back.
All other information is saved but not the settings done with the javascript.
![]() |
-1 |
![]() |
Hi,
its not due to the order of operations....
the values assigned to controls except hidden filed will be cleared at the time of postback. This is problem. if you want maintain the values, you need to save the values in hidden controls or recompute the value at server side....
Vasanthakumar
Software Engineer.
![]() |
1 |
![]() |
This is good to know and you were right about it having to be in hidden fields. As soon as I did that the values where being picked up on the post back. Also, they had to be .net hidden field controls and just not HTML control with the runat on it.
But, if I have more than 3 hidden fields the values stop being picked up. Less and 3 and it is fine. I have 7 items.
Anyone have an idea of what may be causing this?
^_^
![]() |
1 |
![]() |
Hi,
its not like that... you can have how many controls you need...
there is something wrong. please post your code...
Vasanthakumar
Software Engineer.
![]() |
-1 |
![]() |
You could also just make your TextBox an ASP:TextBox and it would retain it's value through PostBacks.
NC...
![]() |
1 |
![]() |
Hi NC,
is it possible to maintain the values assigned by JS for asp:Textbox during the postback?....
Vasanthakumar
Software Engineer.
![]() |
-1 |
![]() |
I'm not at work so I can't post the code but I'll do it when I get into the office. What sort of code are you looking for other than the initial post? It outlines everything I'm doing. I also forgot to mention that after experimenting a bit I discovered that it will pick up the new value regardless if it is a hidden field or textbox as long as I don't have more than 3 fields. Anyway, I'll get the code posted when I get into the office.
Stay tuned. :)
![]() |
1 |
![]() |
I don't understand the 3 fields part. I have had many more than 3 fields with no problems. Maybe you should post some if your code.
NC...
![]() |
-1 |
![]() |
I found the problem and was able to solve it. It turns out it, it was the script that was being called by the scriptmanager for a different part. It was preventing the information from being picked up correctly. The cause was the scriptmanager was only calling 1 function instead of 2 how intended. It was dropping the second call. After a bit of modification to the process of things, it worked great. Therefore, it was an order of things or something like that.
^_^
![]() |
-1 |
![]() |
For your future information, ScriptManager does not call the script, it just inserts it into the rendered page.
NC...
![]() |
-1 |
![]() |