Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

I have a user control which comprise of four buttons. Of these four buttons, I want to change the text of one particular button only on a particular containing page. e.g. one button's text is "Create" I want to change the text of this button on my containing page as "Clear". Is it possible? Please guide me
Posted

You want to use the FindControl method from the containing page:

Button btn = myUserControl.FindControl("ID_OF_BUTTON") as Button;

if(btn != null)
{
   btn.Text = "Clear";
}
 
Share this answer
 
Jim's solution will surely work but here is another way to it.

In user control:

C#
public string ButtonLabel
    {
        get
        {
           return ID_OF_BUTTON.Text;
        }
        set
        {
           ID_OF_BUTTON.Text = value;
        }
    }


And in the containing page:

NameOfUserControl.ButtonLabel = "Clear";
 
Share this answer
 
v2
write that text in a label so that you can check label.text and then
you can change the
button name as button.text="DONE"
 
Share this answer
 
btn.text="clear";
 
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