Solved

AJAX Form Submission using UpdatePanel and UserControls

Posted on 2014-03-07
1
394 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

15 Experts available now in Live!

Get 1:1 Help Now