How to change the value of a control on the main page?

How to change the value of a control, for example. The literal in the user control and that user control is on the main page, and I want to change the value of this literal in the content page.

((System.Web.UI.UserControl)this.Page.Master.FindControl("ABC")).FindControl("XYZ").Text = "";

Here, ABC is the user control, and XYZ is the literal control.

+2
source share
1 answer

The best solution is to expose values ​​through public properties.

Put the following in your control ABCthat contains the control XYZ:

public string XYZText
{
    get
    {
        return XYZControl.Text;
    }
    set
    {
       XYZControl.Text= value;
    }
}

Now you can open it on the main page by adding the following property to MasterPage:

public string ExposeXYZText
{
    get
    {
        return ABCControl.XYZText;
    }
    set
    {
       ABCControl.XYZText = value;
    }
}

, , ( MP - MasterPage):

string text = ((MP)Page.Master).ExposeXYZText;
((MP)Page.Master).ExposeXYZText = "New Value";
+5

Source: https://habr.com/ru/post/1751609/


All Articles