Value persists in asp.net webpage page even when view state and control state are disabled

The value persists in the asp.net webpage page even if I disable view state and control state. The watchdog remains in the postback even after I disabled Enableviewstate

as false for that page and disabled the control state by overriding it SavePageStateToPersistenceMedium()

as empty.

/*value is still preserving in asp.net webform page 
      even if disable view state and control state*/

public class CustomTextBox : TextBox
{
    public CustomTextBox()
    {

    }
     //this method is ipostbackdatahandler one
    protected override void LoadControlState(object savedState)
    {

       //doing ntng here means we are not saving anything by this way
    }
    //this method is ipostbackdatahandler one
    protected override void RaisePostDataChangedEvent()
    {

    }

    protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
    {

        //writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, "Green");
        writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "5px");
        base.AddAttributesToRender(writer);

    }
}

      

How can I resolve this situation?

+3


source to share


1 answer


The value of the textbox is stored in the data of the form post, so ASP.NET will automatically save it.

If you want the textbox to return blank, add code like this, perhaps during prerender.



this.MyTextbox.Text = "";

      

0


source







All Articles