Say you have a page called Test which will get included in Content place holder, then you have to cast page to the relevent type of call the method.
Page
Public Partial Class Test
Inherits Page
Protected Overrides Sub OnLoad(e As EventArgs)
MyBase.OnLoad(e)
End Sub
Public Sub MyMethod()
End Sub
End Class
Master pages
Public Partial Class SiteMaster
Inherits MasterPage
Protected Overrides Sub OnLoad(e As EventArgs)
MyBase.OnLoad(e)
Dim testPage As Test = TryCast(Me.Page, Test)
If testPage IsNot Nothing Then
testPage.MyMethod()
End If
End Sub
End Class
If you have to call this method in much more page implement a BasePage so that you can cast the page to base page type and then call the method
Zath
Star
8057 Points
1772 Posts
Call sub from Master Page
Nov 04, 2010 10:54 PM|LINK
On the content 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)
Now, I want to call the Sub on the content page.
Just can't seem to find a way to do this.
Thanks,
Zath
Charith Guna...
Star
14958 Points
1854 Posts
Re: Call sub from Master Page
Nov 04, 2010 11:09 PM|LINK
Say you have a page called Test which will get included in Content place holder, then you have to cast page to the relevent type of call the method.
Page
Master pages
If you have to call this method in much more page implement a BasePage so that you can cast the page to base page type and then call the method
Charith Gunasekara | FAQ