Link to home
Start Free TrialLog in
Avatar of freezegravity
freezegravity

asked on

How to handle webpart with multiple postbacks (screens)?

Hello,

I am creating a webpart that spans multiple screens. The 3 screens for the end user are,

1. Enter basic information
2. Confirm entered values screen. If you want to make changes, you can go back to screen 1 or move on to screen 3.
3. Success page.

Having written many two screen and one screen webparts before, I am fairly confident that I can get the controls I need rendered just fine.

What I am missing is the logic that goes from screen 1 to screen 3 while preserving all values so that screen 3 can store the values successfully in a list.

What is the best approach for doing this?

Thanks!


SOLUTION
Avatar of Jamie McAllister
Jamie McAllister
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of freezegravity
freezegravity

ASKER

Specifically, See the attached code. When I click Button1, the screen goes blank, Button 2 isn't even loaded.

Can you assist with this?
protected override void CreateChildControls()
{
    this.Controls.Add(Button1);
}

protected void Button1_click(object sender, Eventargs e)
{
    Button1.Visible = false;
    this.Controls.Add(Button2);
}

Open in new window

Create your control instances and add them to the controls collection in CreateChildControls. You can control the conditionality of their display in the Render method, or if it's going to be a lot of [memory] overhead do the conditionality in CreateChildControls so their instances are never created at all.

I wouldn't tend to add controls to the controls collection outside of there.

Further, you could alter the CSSClass property of the controls in your click events and control visibility with CSS.

I am not sure what you mean. Can you show by code sample?

I believe the button event handler can't do much of anything because at that point, CreateChildControls has already been executed and all controls already rendered. How do I get around this problem?

Thanks!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial