2015-06-02 33 views
3

即使禁用視圖狀態和控制狀態,該值仍保留在asp.net webform頁面中。即使在對該頁面禁用Enableviewstate爲false並通過將SavePageStateToPersistenceMedium()替換爲空來禁用控件狀態之後,控件的值仍然保留在回發中。即使禁用視圖狀態和控制狀態,值仍保留在asp.net webform頁面中

/*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); 

    } 
} 

我該如何解決這種情況?

+0

歡迎來到Stack Overflow。您可以通過按下問題下面的「編輯」按鈕來添加您的問題,而不是按評論按鈕。我已經爲你做了修復編輯,以便你現在更有可能得到答案,問題會更好。祝你好運。 –

回答

0

該文本框的值保存在表單發佈數據中,因此ASP.NET將自動保留它。

如果您希望文本框恢復爲空,請在prerender中添加此代碼。

this.MyTextbox.Text = ""; 
+0

我只是學習asp.net webforms,爲了弄清楚它是如何工作的,我試圖禁用它。手動我們可以做........... – Mahesh