简体   繁体   中英

How to access fields in a user control from main page containing that control?

I have a main page and I have a user control on this page. User control has some text fields.

How can I access those fields from my main page?

Thank you

Make the fields available as public properties of your user control. Something like

public class MyControl
{
    public Label LabelX { get { return m_LabelX; } }
    public Label LabelY { get { return m_LabelY; } }
}

where m_LabelX and in your main page then access the label like this

var userControlLabel = ((MyControl)m_UserControl).LabelX;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM