Just started learning ASP.NET, did some practice with TextBox and Button - getting sum of two numbers.
I want the TextBoxes Not to retain their values after clicking the button, by setting the EnableViewState = "false". This doesn't work and by searching posts, I got some explanations on this issue...The problem is, with all the explanations, I can't manage to find a solution.
There are some possible ways I found by searching, to make the TextBox not retain its value:
setting the TextBox to "": TextBox1.Text ="" source: http://aspadvice.com/blogs/joteke/archive/2004/03/15/2273.aspx didn't work for me..
"...mark the text box read-only or marked its visibility false..." source: EnableViewState property in textbox didn't work too...
My code:
<asp:TextBox ID="txtFirstNumber" runat="server" EnableViewState="false"></asp:TextBox>
<asp:TextBox ID="txtSecondNumber" runat="server" EnableViewState="false"></asp:TextBox>
<asp:TextBox ID="txtSum" runat="server" Enabled="False"></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" Text="Add"onclick="btnAdd_Click1" />
code-behind page
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnAdd_Click1(object sender, EventArgs e)
{
int a = Convert.ToInt32(txtFirstNumber.Text);
int b = Convert.ToInt32(txtSecondNumber.Text);
int c = a + b;
txtSum.Text = c.ToString();
}