Results 1 to 3 of 3

Thread: [2005] Page with multiple user controls..

  1. #1

    Thread Starter
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    [2005] Page with multiple user controls..

    Hey guys, I'm trying to modularise my page abit by doing the following,

    Code:
    <%@ Register Src="suppliers/viewsuppliers.ascx" TagName="viewsuppliers" TagPrefix="supp" %>
    <%@ Register Src="suppliers/newsupplier.ascx" TagName="newsupplierform" TagPrefix="supp" %>
    <%@ Register Src="suppliers/deletesupplier.ascx" TagName="deletesupplierform" TagPrefix="supp" %>
    
    
    //And below
    
    
                    <div id="NewSupplierContainer" runat="server">
                        <supp:newsupplierform ID="NewSupplier" runat="server" />
                    </div>
                    <div id="DeleteSupplierContainer" runat="server">
                        <supp:deletesupplierform id="DeleteSupplier" runat="server" />
                    </div>
                    <div id="ViewSupplierContainer" runat="server">
                        <supp:viewsuppliers ID="ViewSupplier" runat="server" />
                    </div>
    And then on Page_Load, I check the arguments,

    Code:
        protected void Page_Load(object sender, EventArgs e)
        {
    
            DeleteSupplierContainer.Visible = false; 
            NewSupplierContainer.Visible = false;
            if (Request.QueryString["action"] != null)
            {
                ViewSupplierContainer.Visible = false;
                switch (Request.QueryString["action"].ToUpper())
                {
                    case "NEW":
                        NewSupplierContainer.Visible = true;
                        break;
                    case "DELETE":
                        DeleteSupplierContainer.Visible = true;
                        break;
                }
    
            }
        }

    However, my faith in the fact that code that is set to Invisible is not run has been proven wrong.

    Anyone have any suggestions on how I could make it so that only one of the 3 pages get loaded at a time?
    Don't Rate my posts.

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: [2005] Page with multiple user controls..

    Instead of having the controls always on the page but set to visible or not. Just add the control you need to add at runtime.

    Add a placeholder to your page and add your controls to that.

    Code:
                Control c;
                switch (Request.QueryString["action"].ToUpper())
                {
                    case "NEW":
                        c = LoadControl("newsupplierform.ascx");
                        c.ID = "NewSupplier";
                        break;
                    case "DELETE":
                        c = LoadControl("deletesupplierform .ascx");
                        c.ID = "DeleteSupplier";
                        break;
                }
                this.placeholder.Controls.Add(c);

  3. #3

    Thread Starter
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: [2005] Page with multiple user controls..

    Awesome, thanks FishCake, that did the trick.
    Don't Rate my posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width