本文整理汇总了C#中System.Web.UI.Page.EnableViewState属性的典型用法代码示例。如果您正苦于以下问题:C# Page.EnableViewState属性的具体用法?C# Page.EnableViewState怎么用?C# Page.EnableViewState使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Web.UI.Page
的用法示例。
在下文中一共展示了Page.EnableViewState属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WebPage
public class WebPage : Page
{
private MyForm myFormObj;
private Label label1;
private Label label2;
private TextBox textBoxObj;
private Button buttonObj;
public WebPage()
{
Page.Init += new System.EventHandler(Page_Init);
}
private void Page_Load(object sender, System.EventArgs e)
{
// Comment the following line to maintain page view state.
Page.EnableViewState = false;
myFormObj.Method = "post";
Controls.Add(myFormObj);
textBoxObj.Text = "Welcome to .NET";
label1.Text = "Enter a name";
buttonObj.Text = "ClickMe";
buttonObj.Click += new EventHandler(Button_Click);
myFormObj.Controls.Add(label1);
myFormObj.Controls.Add(textBoxObj);
myFormObj.Controls.Add(buttonObj);
myFormObj.Controls.Add(label2);
}
private void Button_Click(object sender, EventArgs e)
{
String temp = "<br>Name is " + textBoxObj.Text + "<br>";
temp += "Saved content of previous page is " + ViewState["name"] as String;
label2.Text = temp;
}
protected override void LoadViewState(object viewState)
{
if(viewState != null)
base.LoadViewState(viewState);
}
protected override object SaveViewState()
{
ViewState["name"] = textBoxObj.Text;
return base.SaveViewState();
}
private void Page_Init(object sender, EventArgs e)
{
this.Load += new System.EventHandler(this.Page_Load);
myFormObj = new MyForm();
label1 = new Label();
label2 = new Label();
textBoxObj = new TextBox();
buttonObj = new Button();
}
};