Link to home
Start Free TrialLog in
Avatar of flynny
flynnyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

AJAX Form Submission using UpdatePanel and UserControls

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

ASKER CERTIFIED SOLUTION
Avatar of OriNetworks
OriNetworks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial