How to access content page controls from master page in asp.net

后端 未结 7 1040
一生所求
一生所求 2020-12-13 16:04

it is very easy to access master page control from content page like

protected void Page_Load(object sender, EventArgs e)
{
    // content page load event
          


        
7条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 16:20

    In my opinion it even better to use event raise from Master page and catch this event in contenet page for changing some contenet on this page, for instance. The main advantage is reusability. In future you may want to change content on other content page from the Master page and in this case you should only add event handler to this content page without changing code on master page. Within such approach you needn't hardcode control name from some content page. And moreover you shouldn't add dependency for some content's control at all.

    A sample of implementation you can find here, for example.

提交回复
热议问题