Including User Controls

daria8784

New Member
I am having a small problem with user controls here.<BR><BR>I have a control which holds a few different options for a menu. Depending on what the visitor to the site does depends on what menu he gets shown.<BR><BR>The way I used to do this in ASP normal was with a simple If Else statement and then set a variable in the main page at run time. But this does not seem to work with User controls.<BR><BR>Could someone let me in on the secret of how these things work?<BR><BR>Another quick question<BR><BR>I have my controls in a folder called includes just of my main site url.<BR><BR>How do I set up the tag so that I don't have to change the src everytime I change sub directories.<BR><BR>eg.<BR><BR><%@ Register Tagprefix="CDSC" Tagname="Footer" Src=http://aspmessageboard.com/includes/footer.ascx" %><BR><BR>This is annoying :)> How do I set up the tag so that I don't have <BR>> to change the src everytime I change sub directories<BR><BR>Use non-relative paths:<BR><%@ Register Tagprefix="CDSC" Tagname="Footer" Src="/includes/footer.ascx" %><BR><BR>works like a charm.<BR><BR>>The way I used to do this in ASP normal was with a <BR>> simple If Else statement and then set a variable in <BR>> the main page at run time. But this does not seem <BR>> to work with User controls<BR><BR>In your User control create a server-side script block, if you don't have one already, and add a global variable, like:<BR><BR><script language="vb" runat="server"><BR> Public DisplayMenu as Boolean = True<BR><BR> ...<BR><BR>Now, in your Page_Load event handler, check to see what the value of DisplayMenu is and act accordingly:<BR><BR> Sub Page_Load(sender as Object, e as EventArgs)<BR> If DisplayMenu then<BR> lblMenu.Text = "..."<BR> Else<BR> ...<BR> End If<BR> End Sub<BR></script><BR><BR>Then, when instantiating your User control from an ASP.NET Web page, you can say:<BR><BR><CDSC:Footer runat="server" DisplayMenu="True" /><BR><BR>hth<BR><BR>ALso, consider checking out these two tutorials:<BR>http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=108<BR>http://www.dotnetjunkies.com/tutorials.aspx?tutorialid=113<BR><BR>Happy Programming!<BR><BR>(BTW, if you like those tutorials, you may want to consider picking up a copy of a book I and those tutorial authors worked on:<BR><BR>ASP.NET: Tips, Tutorials, and Code<BR>http://www.amazon.com/exec/obidos/ASIN/0672321432/4guysfromrollaco<BR>)
 
Back
Top