Solved

How to handle webpart with multiple postbacks (screens)?

Posted on 2010-08-29
5
662 Views
Last Modified: 2012-05-10
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!


0
Comment
Question by:freezegravity
  • 2
  • 2
5 Comments
 
LVL 31

Assisted Solution

by:Jamie McAllister MVP
Jamie McAllister MVP earned 100 total points
ID: 33556526
Viewstate is the way to do this. You could also use Session if it's been enabled on your SharePoint server.

http://vspug.com/chadclarkesmossblog/2007/10/10/custom-web-part-building-state-management-tips-and-tricks/
0
 

Author Comment

by:freezegravity
ID: 33560060
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

0
 
LVL 31

Expert Comment

by:Jamie McAllister MVP
ID: 33560385
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.

0
 

Author Comment

by:freezegravity
ID: 33564039
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!
0
 
LVL 5

Accepted Solution

by:
navtej_dhillon earned 400 total points
ID: 33565613
You can do this using ViewState or QueryString or best option could be Ajax, where you just keep changing the inner HTML of webpart depending upon user action.

Alternate way of show/hide could be achieved by creating 3 separate div's with requisite HTML and loading the div on demand.

Regards,
Amit
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now