views:

189

answers:

2

hi, i am having two textboxes and a label in a gridview control, i am adding a javascript function to the second textbox onblur event attribute and display the result in the label, the function works fine and result is displayed in the label, but when i am saving the grid data into the database, the label is returned 0 or empty, but i am able to see the value , how to overcome this.

thanks and regards

+4  A: 

Your label is not persisted in the ViewState because it does not consists as a 'Form' control. You could use a hidden Textbox to accomplish that, there are probably better ways tho.

F.Aquino
i tried with hidden field , it is working on certain systems and not in certain systems , is there any browser settings which is preventing this action. the browser in which it is not working is firefox 3.5.5 any inputs?
sansknwoledge
+1  A: 

Here is a link that answers your question.

http://www.mikesdotnetting.com/Article/65/ViewState-form-fields-labels-and-Javascript

If I understand correctly, (please correct me if I am wrong) it is the IPostBackDataHandler (more info) that handles data in a server input field control when it was changed by the client (Javascript). A label control is not an input field therefore changes made in the client are not saved.

Here is a quote from the link above:

ViewState's job is to manage any changes to the initial state of server controls, if those changes are made programmatically on the server, or if changes made by user interaction are passed to the server. This does not include restoring the values of form inputs such as TextBoxes or the selected item in a CheckBox. There is a common misconception that form values are managed by ViewState. They are not. Never have been. These values are managed and restored purely by IPostBackDataHandler.

IPostBackDataHandler is a massive boon to web developers who were brought up on other server-side technologies, such as classic ASP, PHP etc. In the "olden" days, we used to have to manually wire up every form field to display the originally posted value, so that user's weren't presented with an empty form to fill in all over again, if it had failed server-side validation. IPostBackDataHandler means we never have to do that again.

As mentioned in another answer using a hidden value to also hold the changes made by the Javascript should work.

orandov