简体   繁体   English

如何访问放置在母版页用户控件中的用户控件

[英]how to access user control placed in master pages's user control

I need to access a user control from master page but user control is not placed directly in master page. 我需要从母版页访问用户控件,但用户控件未直接放在母版页中。 It has this hierarchic: 它具有以下层次结构:

Master Page > HeaderUserControl > LoginUserControl > Login button and Logout botton 主页> HeaderUserControl> LoginUserControl>登录按钮和注销按钮

Requirement: 需求:

I need to call logout method of logout button. 我需要调用注销按钮的注销方法。 Unfortunately I am not getting what can be best design to do that. 不幸的是,我没有得到最好的设计来做到这一点。

Please advise and help. 请指教和帮助。

Thanks 谢谢

创建一个httphandler并移动注销代码,您可以通过调用该处理程序来使用它。

As @SimonWhitehead said, you should add a class and call the Logout method from both the MasterPage and the LoginControl . 正如@SimonWhitehead所说,您应该添加一个类,并从MasterPageLoginControl调用Logout方法。 But if you insist, this is a way of doing it, pretty much making the method visible to the next level: 但是,如果您坚持要这样做,那么这是一种方法,几乎​​可以使该方法在下一级可见:

LoginUserControl : LoginUserControl

Public Sub DoLogout()
    'Do something'
End Sub

Protected Sub Logout_Click(sender As Object, e As EventArgs) Handles Logout.Click
    DoLogout()
End Sub

HeaderUserControl : HeaderUserControl

Public Sub DoLogout()
    Me.LoginUserControl.DoLogout()
End Sub

and finally 最后

MasterPage : 母版页

Protected Sub Logout_Click(sender As Object, e As EventArgs) Handles Logout.Click
    HeaderUserControl.DoLogout()
End Sub

This would call your method in the LoginUserControl control. 这将在LoginUserControl控件中调用您的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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