[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?
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);
Re: [2005] Page with multiple user controls..
Awesome, thanks FishCake, that did the trick. :D