Multiview and viewstate

Discussion in 'ASP .Net' started by James Crosswell, Dec 11, 2007.

  1. I noticed something interesting when using the Multiview control and was
    wondering if someone could shed some light on the inner workings of all
    of this so I can better understand what's going on here.

    Basically I'm using the Multiview as a kind of wizard with back/next
    buttons. At step one, I ask a question... let's say "How old are
    you?"... and I use the response to this question to determine the
    contents of the controls on subsequent steps of the multiview.

    To keep things simple, let's imagine that step has a label that says "A
    year ago you were x years old" and step 3 in my little wizard has an
    equally useless label that says "Next year you'll be y" where x = age -
    1 and y = age + 1...

    Now, when I'm writing code in the "Next" button in the view for step 1,
    I first change the active view in my multiview control, then I inspect
    the value of the ageTexEdit.Text control and use this to set the text
    for steps 2 and 3 of the wizard... something like:

    // Set active view

    // Read in response to step one and update steps 2 and 3 accordingly
    int age = int.Parse(ageTexEdit.Text);
    step2Label.Text = String.Format("A year ago you were {0} years old",
    age - 1);
    step3Label.Text = String.Format("Next year you'll be {0}", age + 1);

    Also, presume that before any of the code above has executed the
    properties for step2Label.Text and step3Label.Text are "step 2" and
    "step 3" resepectively.

    Now, if I now fire up my wizard and enter my age as "10" and click on
    the next button, in step 2 everything looks as it should... it says "A
    year ago you were 9 years old". However, when I click on the "Next"
    button in step 2 of the wizard, which simply does the following:


    The text in step three still says "step 3"... so the code that was run
    successfully in the On Click event handler for the next button in step
    one DIDN'T do what I was expecting. It set the value of step3Label.Text
    correctly, however this value did NOT get stored in the viewstate for
    the form.

    Can anyone explain to me why this is the case?

    By the way, it's easy enough to work around this by setting the text for
    step2Label and step3Label in the ActiveViewChanged event of the
    multiview when the view that each control is contained in becomes
    visible/active. So I'm not looking for a "workaround" to this - that's
    very simple. I'm simply looking to better understand the mechanics of
    all this and understand why the actual behavior is not what I was expecting.


    Best Regards,

    James Crosswell LLC
    James Crosswell, Dec 11, 2007
    1. Advertisements

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. Mavenos

    Ajax and .net multiview control

    Mavenos, Feb 2, 2006, in forum: ASP .Net
  2. Liming

    Multiview and browser back button

    Liming, Apr 20, 2006, in forum: ASP .Net
    Joerg Jooss
    Apr 20, 2006
  3. multiview and validators

    , Sep 8, 2006, in forum: ASP .Net
  4. Replies:
  5. Andy B
    Andy B
    Dec 29, 2008

Share This Page