asp.net - C# adding controls in site master wont reference in asp:loginView -


i have site master i'm adding few controls 1 being label updates programmatically. i'm not sure why in second example cant reference object, if maybe understanding of how scope works in site master wrong. assistance appreciated!

this "clubname" label works intended

 <div class="main">      <asp:label id="clubname" runat="server"></asp:label> </div> 

although 1 doesnt (object reference not set instance of object)

<asp:loginview id="headloginview" runat="server" enableviewstate="false">                 <anonymoustemplate>                     [ <a href="~/account/login.aspx" id="headloginstatus" runat="server">log in</a> ]                 </anonymoustemplate>                 <loggedintemplate>                     welcome <span class="bold"><asp:loginname id="headloginname" runat="server" /></span>!                     [ <asp:loginstatus id="headloginstatus" runat="server" logoutaction="redirect" logouttext="log out" logoutpageurl="~/"/> ]                     <asp:label id="clubname" runat="server" text="label"></asp:label>                 </loggedintemplate>  </asp:loginview> 

my code behind code simply

public partial class sitemaster : system.web.ui.masterpage {     protected void page_load(object sender, eventargs e)     {         nameclub.text = "hello";     } 

and exception error:

 object reference not set instance of object.  description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.   exception details: system.nullreferenceexception: object reference not set instance of object. 

label clubname= headloginview.findcontrol("clubname") label; if(clubname != null)      clubname.text =   "hello"; 

your aspx label id clubname in code access nameclub. anyway can't access controls inside loginview directly. use findcontrol method , control above.

you better read how to: access server controls id


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -