即使我禁用 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/