Solved

How to handle webpart with multiple postbacks (screens)?

Posted on 2010-08-29
5
650 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

16 Experts available now in Live!

Get 1:1 Help Now