Home > Net >  ASPX - Reading master page element returns null
ASPX - Reading master page element returns null

Time:02-03

I have an anchor link in the master page and trying to assign its href in code behind, but the element is null.

Default.master

<body>
   <header>
      <asp:Hyperlink ID="ancLogout" runat="Server" Text="Logout" />
   </header>
</body>

Default.master.cs

protected void Page_Load(object sender, EventArgs e)
{
  if (ancLogout != null)
    {
      ancLogout.NavigateUrl = String.Format("{0}?logout=1", HttpContext.Current.Request.Url.AbsoluteUri); 
    }
}

The ancLogout is always null.

CodePudding user response:

have just tried your exact code and theres no issues for me? ... maybe a lower case 'S' on server but shouldn't matter

  • Related