Handling events generated by a Master Page in a content placeholde

G

Guest

I have a problem, I have an event declared in a Master Page, and I want to
use in a Content Page holder of a Content Page. When I want to create the
method to handle the event, I can njot reference the Master Page event, in
its place IntelliSense shows me a Delegate Sub EventHandler. I am new with
events managements, so any help and guiadance will be appreciated.

Federico
 
G

Guest

1- In the content page you need to get a reference to the master page like
this:
<%@ MasterType virtualPath="~/MasterPage.master"%>

http://msdn2.microsoft.com/en-us/library/c8y19k6h.aspx

2- Assuming that the master page raises and event (let's call it
MasterPageEvent1 that has a delegate named MyEventHandler) then you can wire
up an event handler in the content page like this:

Master.MasterPageEvent1+= new MyEventHandler(Master_MasterPageEvent1);

3- Write a function:
void Master_MasterPageEvent1(object sender, EventArgs e)
{
//steps within handling the event
}
For more detail on raising and consuming events:
http://msdn2.microsoft.com/en-us/library/9aackb16.aspx
 
G

Guest

I´m developing using VB 2005, I can not view the public event declarated in
the master page, from the content page, so i'm unable to wire up the event
with the handler.
Here is the source code from MasterPage

Partial Class MasterPage
Inherits System.Web.UI.MasterPage

Event event1(ByVal sender As Object, ByVal e As EventArgs)

Protected Sub guardarImageButton_Click(ByVal sender As Object, ByVal e
As System.Web.UI.ImageClickEventArgs) Handles guardarImageButton.Click
RaiseEvent event1(Me, e)
End Sub

End Class

Public Delegate Sub ManejadorEvento(ByVal sender As Object, ByVal e As
EventArgs)

.....and here the code of content page

artial Class _Default
Inherits System.Web.UI.Page

Public Sub metodo()

End Sub

Protected Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Init
AddHandler Master.event1, AddressOf metodo ' this is the wrong line
End Sub
End Class

The error reported is:"'event1' is not an event of 'System.Web.UI.MasterPage'.

Please give me an example in VB 2005

Thanks
 
G

Guest

The link I posted previously has an example in VB that can guide you:
http://msdn2.microsoft.com/en-us/library/9aackb16.aspx

Briefly you needed to modify your code to look like this:

Public Delegate Sub MasterPageEventHandler1(sender As Object, e As
System.Web.UI.ImageClickEventArgs)

Partial Class MasterPage
Inherits System.Web.UI.MasterPage

Public Event1 As MasterPageEventHandler1


Protected Sub guardarImageButton_Click(ByVal sender As Object, ByVal e
As System.Web.UI.ImageClickEventArgs) Handles guardarImageButton.Click
RaiseEvent event1(Me, e)
End Sub

End Class

Then In the content page you need to get a reference to the master page like
this:
<%@ MasterType virtualPath="~/MasterPage.master"%>
 
G

Guest

Phillip thank you for your help. Now it works.

Phillip Williams said:
The link I posted previously has an example in VB that can guide you:
http://msdn2.microsoft.com/en-us/library/9aackb16.aspx

Briefly you needed to modify your code to look like this:

Public Delegate Sub MasterPageEventHandler1(sender As Object, e As
System.Web.UI.ImageClickEventArgs)

Partial Class MasterPage
Inherits System.Web.UI.MasterPage

Public Event1 As MasterPageEventHandler1


Protected Sub guardarImageButton_Click(ByVal sender As Object, ByVal e
As System.Web.UI.ImageClickEventArgs) Handles guardarImageButton.Click
RaiseEvent event1(Me, e)
End Sub

End Class

Then In the content page you need to get a reference to the master page like
this:
<%@ MasterType virtualPath="~/MasterPage.master"%>

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top