I am having a problem in which two controls which are added programmatically are trying to load each other viewstate, I want to clear the viewstate before loading the controls, I tried Viewstate.Clear but it did nothing, when I disable viewstate on the container of my controls everything works fine except that the control's state is not kept. Is there a way to clear viewstate of just a specific control?
By default, view state data is stored in the page in a hidden field and is encoded using base64 encoding. In addition, a hash of the view state data is created from the data by using a machine authentication code (MAC) key.
The only possible way to remove the ViewState Hidden Field is by removing it from the generated HTML of the Page with the help of Regular Expressions. In order to achieve the above objective, the Render event will be overridden and the ViewState Hidden Field will be removed from the generated HTML.
To disable ViewState for a page To disable ViewState for a single page, set the EnableViewState attribute in the @ Page directive to false, as in the following: <%@ Page Language="C#" EnableViewState="false" AutoEventWireup="true" CodeFile="URLRouting. aspx.
Yes ,
string controlName = "name of control";
ViewState[controlName] = null;
// create control, add it to the page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With