Solved

AJAX Form Submission using UpdatePanel and UserControls

Posted on 2014-03-07
1
393 Views
Last Modified: 2014-03-20
Hi all,

I have a number of usercontrols which aI want to seamlessly run through using AJAX (i.e. without leaving the page).

1. Signup form
2. Confirmation Form.
3. Completion Form.

When the user first navigates to the site they will be navigated to the Signup form. Once this is completed they will click the 'signup' button in the .ascx control.

Now from here I want to load move to the next usercontrol. Now how can I bubble the click request from the ascx control to the page? and set the current usercontrol to the viewstate in case of postback?

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>   
            <asp:PlaceHolder ID="PlaceHolderPageContent" runat="server"></asp:PlaceHolder>
        </ContentTemplate>
    </asp:UpdatePanel>

Open in new window


private const string BASE_PATH = "~/usercontrols/";

    private string LastLoadedControl
    {
        get
        {
            return ViewState["LastLoaded"] as string;
        }
        set
        {
            ViewState["LastLoaded"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LastLoadedControl = BASE_PATH + "SignupForm.ascx";
        }

        LoadUserControl();
    }

    private void LoadUserControl()
    {
        string controlPath = LastLoadedControl;

        if (!string.IsNullOrEmpty(controlPath))
        {
            PlaceHolderPageContent.Controls.Clear();
            UserControl uc = (UserControl)LoadControl(controlPath);
            PlaceHolderPageContent.Controls.Add(uc);
        }
    }

Open in new window

0
Comment
Question by:flynny
1 Comment
 
LVL 17

Accepted Solution

by:
OriNetworks earned 500 total points
ID: 39912523
Do you have any objections to having all of the UserControls in the Content section and set Visible="False" as the default for all of them? You can then use the pageload event to check which controls should be visible. Otherwise you would need to dynamically load all controls on every postback and that can get messy.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

706 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

19 Experts available now in Live!

Get 1:1 Help Now