Set value of Viewstate from Javascript

12,610

You simply can not assign value in client side.

  1. Either you have to pass it through hidden field while submitting form or
  2. Call ajax from javascript and access the ViewState server side.
Share:
12,610
user3739515
Author by

user3739515

Updated on June 14, 2022

Comments

  • user3739515
    user3739515 almost 2 years

    I am working on asp.net application. Where for a page I have to clear the value of the controls(like textbox and dropdownlist,etc), also i have to remove the value of a ViewState. Initailly i was doing it from codebehind, so o problem was there. But now the problem arise when i tried reset the value of controls using client side , say

    document.getElementById('<%= txtTextBox.ClientID %>').value ='';
    

    but the problem i am facing is that i cannot set the viewstate value from clientside. my i have to clear to viewstate one is a simple variable say ViewState["NameOfUser"],and another one is converting a datatable into viewstate say,

    ViewState["dataTable"] = dt;
    

    Thanks and regards

  • user3739515
    user3739515 almost 10 years
    any sample or reference link will be very much helpful.
  • cinek
    cinek about 9 years
    do you have an access to ViewState property when doing ajax call which is static method?