Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change ascx menu link color 1

Status
Not open for further replies.

occas

Technical User
Jan 14, 2004
164
US
i have webpages where i use an ascx control page for the menu. it is nothing more than a table with x amount of rows with hyperlinks.

i would like to be able to change the color of the selected hyperlink, depending upon which one is selected.
i can't find out how to have any control over those hyperlinks that are in the ascx page when it is called by whatever page is using it.
ty.
 
Whether you dynamicaly load the control on each page through the code or have it embedded, you should be able to find an appropriate hyperlink in the control and set it's color.
Code:
[b]user control html:[/b]
<asp:HyperLink ID=&quot;hl1&quot; Runat=server NavigateUrl=&quot;[URL unfurl="true"]www.msn.com&quot;[/URL] Text=&quot;MSN&quot; />
<br>
<asp:HyperLink ID=&quot;hl2&quot; Runat=server NavigateUrl=&quot;[URL unfurl="true"]www.monster.com&quot;[/URL] Text=&quot;Monster&quot; />

[b]container page html:[/b]
<asp:PlaceHolder ID=&quot;plControl&quot; Runat=server />
[b]container page code behind:[/b]
private void Page_Load(object sender, System.EventArgs e)
{
  Control myMenu = Page.LoadControl(&quot;Menu.ascx&quot;);
  HyperLink firstLink = (HyperLink)myMenu.FindControl(&quot;hl1&quot;);
  HyperLink secondLink = (HyperLink)myMenu.FindControl(&quot;hl2&quot;);

  firstLink.ForeColor = Color.Green;
  secondLink.ForeColor = Color.Red;

  plControl.Controls.Add(myMenu);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top