Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am trying to change the text of a button in master page from an aspx page.

I put the following in the master page:

HTML
public LinkButton LButton
    {
        get { return LButton; }
        set { LButton = value; }
    }


then i added the following in the .aspx page:

<%@ MasterType VirtualPath="Site.Master" %>


lastly in the code behind i put:

HTML
Master.LButton.Text = "logout";



i get an error that says:

stackoverflow exception by user code! and it is pointing at:


HTML
public LinkButton LButton
    {
        get { return LButton; }
        set { LButton = value; }
    }


as a loop!

please help...
Posted

Your "get" is returning LButton, so will go into the same get and so on. If you have a LinkButton you're trying to return then your property has to be called something other than LButton.

XML
<asp:LinkButton ID="MyLinkButton" runat="server" />


C#
public LButton {get {return MyLinkButton;} }


Or if you just want to create a property called LButton on the master page you will use elsewhere just use

C#
public LinkButton {get;set;}


However it is best practise to not expose controls like this but to set up properties for the values you want to change, so have a string property called "ButtonLabel" or something, and the master page updates the LinkButton when the property is set.
 
Share this answer
 
I found a solution...

I only put the following in the .aspx code:

Button l1 = Page.Master.FindControl("Button1") as Button;
        l1.Text = "logout"; 



and it works :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900