开发者

How can I call the Sub on the content page?

How can I call the Sub on the content page?

On the c开发者_如何学JAVAontent page, there is let's say this:

Public Sub MySub()

End Sub

On the master page I have this:

Dim cph As ContentPlaceHolder = CType(Page.Form.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)


Why do you need this? You can't be sure to have a particular contentpage. A Masterpage's purpose is re-usability and therefore many pages should use it. Why you need to access a special page?

What you could do is, add an event to the Masterpage, raise it when necessary and handle it in the ContentPage. For example...

in Master:

Partial Public Class ERPMaster
    Inherits System.Web.UI.MasterPage

    Public Event MasterLoaded(ByVal master As MasterPage)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        RaiseEvent MasterLoaded(Me)
    End Sub

In Content:

Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
    AddHandler DirectCast(Master, ERPMaster).MasterLoaded, AddressOf MasterLoaded
End Sub

Private Sub MasterLoaded(ByVal master As MasterPage)
   MySub()
End Sub

Public Sub MySub()
End Sub


I assume that you are using ASP.NET?

Do you have a MasterType directive at the top of the content page file? If so, you can simply call functions on the master page using the following syntax:

Master.MySub()

The Master property of the content page is already typed to the page specified in the MasterType directive, so you can easily access any of the functions that it defines.

See MSDN for more information on interacting with master and client pages: http://msdn.microsoft.com/en-us/library/c8y19k6h(v=VS.100).aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜