ViewState chaos

Discussion in 'ASP .Net' started by =?Utf-8?B?dGhlIGZyaWVuZGx5IGRpc3BsYXkgbmFtZQ==?=, Sep 8, 2005.

  1. 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.
     
    =?Utf-8?B?dGhlIGZyaWVuZGx5IGRpc3BsYXkgbmFtZQ==?=, Sep 8, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?dGhlIGZyaWVuZGx5IGRpc3BsYXkgbmFtZQ==?=

    Mythran Guest

    "the friendly display name"
    <> wrote in message
    news:...
    > 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
     
    Mythran, Sep 8, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maximilian Michel

    Class Chaos

    Maximilian Michel, Jun 28, 2004, in forum: Python
    Replies:
    9
    Views:
    433
    Reinhold Birkenfeld
    Jun 28, 2004
  2. Danno
    Replies:
    22
    Views:
    695
    Danno
    Oct 18, 2006
  3. epicwinter
    Replies:
    11
    Views:
    630
    kevin cline
    Apr 27, 2007
  4. Ian Semmel

    CSS = Chaos ?

    Ian Semmel, Oct 21, 2007, in forum: ASP .Net
    Replies:
    10
    Views:
    728
    Kevin Spencer
    Oct 25, 2007
  5. dorayme
    Replies:
    3
    Views:
    416
    dorayme
    Apr 3, 2009
Loading...

Share This Page