gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 13:13:39 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com