Hi,
I am in process of learning ASP.net. I need to know how to change class of a link which is in Mater page from Default.aspx
For example, in following example I would like to change/update the class of “Home” link.
<div align="right">
<a href="Default.aspx" id="lnkHome" class="">Home</a>
<a href="AboutUs.aspx" id="lnkAbout" class="">About Us</a>
<div class="Clear"></div>
</div>
As I am learning ASP.net, so please suggest the ways to do above.
Thanks!
On your master page code behind create a method like this:
public string MyLinkClass
{
set { mylink.attributes.add(“class”,value; }
}
Then on any page you like to set the class for that link:
MyMasterPage master=(MyMasterPage)this.Page.Master;
if(master!=null)
{
master.MyLinkClass=“someclass”;
}
Hi,
Thanks for your response.
The given solution is not working on my end, as it says “lnkHome” is not declared. Again the html code I have is:
<a href=“Default.aspx” id=“lnkHome” class=“”>Home</a>
Is there any way to access HTML elements (not asp.net html elements that run at server)?
you are missing the runat=“server” attribute.
<a href=“Default.aspx” id=“lnkHome” class=“”>Home</a>
should be
<a href=“Default.aspx” id=“lnkHome” runat=“server” class=“”>Home</a>