Within a GridView I have several TemplateFields. The controls within these fields are set to runat=”server” so I can access them from the codebehind. However, several of these fields values may dynamically change during the course of filling out the information using JQuery. Upon submission of the form when I attempt to process each row’s data, the Value returned for any field that was edited client side using JQuery still reflects the original value assigned during data binding. For example if the field “Hours” was blank when the GridView was databound, but using JQuery I change the value to 350, then in the code behind when I do
string Hours = ((HtmlInputText)row.FindControl("Hours")).Value;
it still returns blank instead of the 350 assigned client side. How do I access the CURRENT value of that field?
The simple answer to this question is that server controls hold the most recent values they were assigned before being posted to the server. You should be getting
350from that control if that was the last thing it was set to.You could try instantiating an actual
HtmlInputTextobject and look at it in debug mode to see if you retrieved the object your looking for successfully.Being in a GridView template, asp.net might have modified it’s
id:1) Are you sure its value was successfully set in jQuery.
2)Are you sure you are successfully retrieving the object in your code-behind?