Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ViewState question

Reply
Thread Tools

ViewState question

 
 
Ilyas
Guest
Posts: n/a
 
      01-07-2010
Hi all

I have the following in my aspx:

<asp:TextBox runat="server" ID="txt1" EnableViewState="false" /
>

+
<asp:TextBox runat="server" ID="txt2" />
=
<asp:Label runat="server" ID="lblResult" />

<br /><br />
<asp:Button runat="server" ID="btnAdd" OnClick="btnAdd_Click"
Text="Add" />

and in my code behind I have:
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnAdd_Click(object sender, EventArgs e)
{
lblResult.Text = (int.Parse(txt1.Text) + int.Parse
(txt2.Text)).ToString();
}

When I enter 1 in the first box and 2 in the second, then click the
add button I get the answer appearing but the first textbox still
remembers the number entered even though I said
EnableViewState="false"

I dont want the first textbox to remember its value across postback -
how can I achieve this?

Thanks
 
Reply With Quote
 
 
 
 
Gregory A. Beamer
Guest
Posts: n/a
 
      01-07-2010
Ilyas <(E-Mail Removed)> wrote in news:5eacb098-018f-
http://www.velocityreviews.com/forums/(E-Mail Removed):

> I dont want the first textbox to remember its value across postback -
> how can I achieve this?


Clear it after you use it.

This is NOT a viewstate issue, as the value has not been stored in
ViewState at that time. It is an issue with the default way a browser
based control works. Solution:


protected void ClearForm()
{
txt1.Text = string.Empty;
txt2.Text = string.Empty;
}

protected void btnAdd_Click(object sender, EventArgs e)
{
lblResult.Text = (int.Parse(txt1.Text) + int.Parse
(txt2.Text)).ToString();
ClearForm();
}

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with ViewState: "function 'ViewState.get_Item' evaluated and returned null" Steph ASP .Net 2 05-11-2011 02:35 PM
Errors: Failed to load viewstate. & Validation of viewstate MAC failed. sck10 ASP .Net 6 09-01-2006 05:59 PM
Loading usercontrols, viewstate problem, slighly different from all others "viewstate uc problems" please help... ujjc001 ASP .Net 0 07-27-2005 01:52 PM
Viewstate errors... how do I get viewstate working? mark ASP .Net Building Controls 0 02-20-2004 02:17 PM
Corrupted ViewState (Yes, another issue concerning viewstate) Ben Rush ASP .Net 2 12-05-2003 04:17 PM



Advertisments