How to set c # variable value from javascript

I make an ajax request and save my answer in a hidden field. I do 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 onclick event button or something like that. Just enter a hidden input type

+3
source share
1 answer

If the asp.net HidenField webControl value matters, you only need the following:

Aspx page:

        <asp:hiddenfield id="hf_MyValue"
          value="whatever" 
          runat="server"/>

Cs page:

string value = hf_MyValue.Value;

If you want to do something with a value when it is assigned to handle the onValueChanged event:

        <asp:hiddenfield id="hf_MyValue"
          onvaluechanged="ValueHiddenField_ValueChanged"
          value="whatever" 
          runat="server"/>

asp.net HiddenField, javascript #, , , .

/. Javascript # .

+5

Source: https://habr.com/ru/post/1774449/


All Articles