即使禁用视图状态和控件状态,仍会在asp.net webform页面中保留值

时间:2015-06-02 11:01:10

标签: html asp.net webforms

即使我禁用了视图状态和控件状态,该值仍保留在asp.net webform页面中。即使我对该页面禁用Enableviewstate为false并且通过将SavePageStateToPersistenceMedium()覆盖为空来禁用控制状态,控制的值仍会保留在回发中。

/*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's one
    protected override void LoadControlState(object savedState)
    {

       //doing ntng here means we are not saving anything by this way
    }
    //this method is ipostbackdatahandler's 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);

    }
}

我该如何解决这种情况?

1 个答案:

答案 0 :(得分:0)

文本框的值保存在发布数据的表单中,因此ASP.NET将自动保留它。

如果您希望文本框返回空白,请添加此类代码,可能在预呈现期间。

this.MyTextbox.Text = "";