Solved

How to handle webpart with multiple postbacks (screens)?

Posted on 2010-08-29
5
687 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to just get time from a date 6 48
Why use this lambda? 12 67
Set arraylist as datatable 2 13
vb.net application has warrnings about VB6 calls. 2 19
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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