How to set a C# variable value from javascript

I’m making an ajax request and storing my response in an hidden field.I’m doing this through javascript using getelementbyid.value.This javascript function is on body onload.Now after I get this value I would like to use this in C#.I can’t have any button onclick event or anything of that sort.Just have a …

via Asp.Net Developed Tutorials » Search Results » ajax:

How to set a C# variable value from javascript

I’m making an ajax request and storing my response in an hidden field.I’m doing this through javascript using getelementbyid.value.This javascript function is on body onload.Now after I get this value I would like to use this in C#.I can’t have any button onclick event or anything of that sort.Just have a hidden input type
………………………………………

If an asp.net HidenField webControl has a value then all you need to do is the following:
aspx page:
value=”whatever”
runat=”server”/>cs page:
string value = hf_MyValue.Value;If you want to do something with the value when it’s assigned handle the onValueChanged event:
onvaluechanged=”ValueHiddenField_ValueChanged”
value=”whatever”
runat=”server”/>While you CAN use a value of an asp.net HiddenField that is set using javascript in C# make sure that you understand that this can only be done after a postback.
Here is some info on the Client/Server relationship. Javascript and C# respectively in your question.

For more info: How to set a C# variable value from javascript

Asp.Net Developed Tutorials » Search Results » ajax

How to set a C# variable value from javascript

Share this post:

Related Posts

Leave a Comment