INCLUDE in ASPX

  • Thread starter Thread starter Lubo¹ ©lapák
  • Start date Start date
L

Lubo¹ ©lapák

Hi,
I have the main page "default.aspx". I have also UserControls
"content1.ascx" and "content2.ascx". How can I write in "default.aspx" this:

if true then
show content1.ascx
else
show content2.ascx

I know I create in HTML code of "default.aspx" this line:
'<content1:content1 id="content" runat="server" />' then in the page is the
content1, but how can i manage this dynamically?
 
You can set the visible property of your web control to true/false to achieve
this.

Regards,

Deepak
[I Code, therefore I am]
 
In addition to Deepak's suggestion, you might look at the LoadControl and
use a placeholder. Something like this should work:

string controlName;
if (whatever)
{
controlName = "Content1.ascx";
}
else
{
controlName = "Content2.ascx";
}
this.myPlaceHolder.Controls.Add(LoadControl(controlName));
 
Back
Top