[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

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

0
flynny
Asked:
flynny
1 Solution
 
OriNetworksCommented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now