Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

ViewState chaos

 
 
=?Utf-8?B?dGhlIGZyaWVuZGx5IGRpc3BsYXkgbmFtZQ==?=
Guest
Posts: n/a
 
      09-08-2005
Following problem:

I have on the page one (graphic-)button (its click even is wired), some
other stuff and of course the page_load function

Page_Load function has the following entry:

{
if (!Page.IsPostBack)
{
counttextboxes = 0;
ViewState.Add("counttextboxes", counttextboxes);

}

counttextboxes = (int) ViewState["counttextboxes"];


Label1.Text = counttextboxes.ToString();

}



ImageButton1_Click has:

{

counttextboxes = (int) ViewState["counttextboxes"];
counttextboxes++;
ViewState.Add("counttextboxes", counttextboxes);


Label2.Text = Convert.ToString(counttextboxes);

}


as you guessed, the problem is counttextboxes (an int, declared as protected
in the class).

If I click on the first button, thus activating button1_click,
counttextboxes gets indeed bigger. But on page_load (when I test it) it is
always one number smaller than it's on Imagebutton1_click.


If Label1 displays 5, label2 displays 6.


How to even them up? _Without_ this method on page load by the way:

if (Convert.ToBoolean(counttextboxes))
counttextboxes = counttextboxes + 1;

Thank you for your time.
 
Reply With Quote
 
 
 
 
Mythran
Guest
Posts: n/a
 
      09-08-2005

"the friendly display name"
<(E-Mail Removed) m> wrote in message
news:(E-Mail Removed)...
> Following problem:
>
> I have on the page one (graphic-)button (its click even is wired), some
> other stuff and of course the page_load function
>


Page_Load executes before control events execute. So, you are displaying
the value of the counttextboxes value before you are incrementing it in the
click event.

Mythran

 
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
Name that worm--plan looks to cut through chaos Imhotep Computer Security 1 09-25-2005 12:57 PM
Class Chaos Maximilian Michel Python 9 06-28-2004 08:12 PM
Corex CardScan 6.0.6/Isbister Time & Chaos 6.0.2.5 anon Computer Support 0 05-30-2004 09:14 PM
DVD Verdict reviews: SITCOM, CHAOS, RADIO, AMANDLA!, and more! DVD Verdict DVD Video 0 02-24-2004 10:04 AM
mini USB cable chaos Phil Schuman Digital Photography 13 12-03-2003 09:20 AM



Advertisments