Auto Ad Code

Tuesday, October 26, 2010

Accessing client side updated value at Server side

Often we use Javascript to update some hidden fields or some dropdown, textbox etc. Its ok and is a quick approach but whats the issue with it?
The only issue we face is that when we try to access the value of such controls at server side we always get the previous value i.e. the value which was there when page was posted last time.
Whats the solution to get the updated value i.e. the value which was updated at client side using Javascript?
Its pretty much easy and straight. You just have to use the Request.Form at server side.

Let us suppose the control name is txtTest and its value is update at client side using Javascript. We will using following statement to get the updated copy.

VB
Dim tmpStr as String = Request.Form("txtTest").Tostring()

C#
String tmpStr = Request.Form["txtTest"].ToString();

No comments:

Post a Comment