[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to handle webpart with multiple postbacks (screens)?

Posted on 2010-08-29
5
Medium Priority
?
703 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 32

Assisted Solution

by:Jamie McAllister MVP
Jamie McAllister MVP earned 400 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 32

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 1600 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month19 days, 4 hours left to enroll

834 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