E
Eran Amitai
I have the simplest web page (using code-behind):
<body>
<%# MyText %>
two buttons - button1 and button2
</body>
My code-behind web page is very simple too:
public class WebForm3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button1;
protected string MyText;
private void Page_Load(object sender, System.EventArgs e)
{
//DataBind(); // Don't want to bind here!
}
// Web Designer code omitted
private void Button1_Click(object sender, System.EventArgs e)
{
MyText = "In button1 handler";
DataBind();
}
}
I don't have a handler for button 2 (it only submits the page), and I DON'T DataBind in the PageLoad function. I only DataBind in the button1 handler.
Here's my problem/question: when I click on button1, I see the text "In button1 handler" on the page, as expected. However, if I click button2, the text doesn't disappear, which was really surprising to me. How does the bound text persist there? I know it has something to do with view state, because the latter changes when button1 is initially pressed. That is also the only way the server can know what the string is. I just haven't seen any documentation linking between binding literal text and view state. How do I disable this (i.e. make sure the bound text isn't saved in view state)?
Thanks,
Eran
<body>
<%# MyText %>
two buttons - button1 and button2
</body>
My code-behind web page is very simple too:
public class WebForm3 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button1;
protected string MyText;
private void Page_Load(object sender, System.EventArgs e)
{
//DataBind(); // Don't want to bind here!
}
// Web Designer code omitted
private void Button1_Click(object sender, System.EventArgs e)
{
MyText = "In button1 handler";
DataBind();
}
}
I don't have a handler for button 2 (it only submits the page), and I DON'T DataBind in the PageLoad function. I only DataBind in the button1 handler.
Here's my problem/question: when I click on button1, I see the text "In button1 handler" on the page, as expected. However, if I click button2, the text doesn't disappear, which was really surprising to me. How does the bound text persist there? I know it has something to do with view state, because the latter changes when button1 is initially pressed. That is also the only way the server can know what the string is. I just haven't seen any documentation linking between binding literal text and view state. How do I disable this (i.e. make sure the bound text isn't saved in view state)?
Thanks,
Eran