html - 即使禁用 View 状态和控件状态,该值仍保留在 asp.net webform 页面中

标签 html asp.net webforms

即使我禁用 View 状态和控件状态,该值仍保留在 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);

    }
}

我该如何解决这种情况?

最佳答案

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

如果您希望文本框返回为空,请添加这样的代码,也许在预呈现期间。

this.MyTextbox.Text = "";

关于html - 即使禁用 View 状态和控件状态,该值仍保留在 asp.net webform 页面中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30594200/

相关文章:

javascript - 将事件类添加到当前事件链接

javascript - Bootstrap 时间选择器不显示时间选择器选项

javascript - 有什么方法可以将参数传递给 $.change() 方法吗?

c# - HTTPContext 在 ASP.NET 和 iis express 中找不到客户端 CAC 证书

c# - 无法访问 session asp.net 核心

c# - 使用 Javascript 向框添加值并刷新。然后在代码隐藏中获取值

javascript - 移动菜单定位

javascript - __DoPostback 在执行部分回发时回发禁用控件的值

javascript - 服务器正在尝试将 HTML 表内的 Repeater 控件转换为 HtmlTableRow

c# - 从 ListBox 中选择多个项目导致 Collection 被修改;枚举操作可能无法执行