accessing controls in master page and adding event to content page

Hi

 I've currently got a control on my master page and i'm trying to write an even on the content page that fires when the button is clicked, I don't think it is working though.

Can someone help? The code is below:

 masterpage

<asp:ImageButton id="imgButton" runat="server"/>

code behind

Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load, Me.Load

Public ReadOnly Property lnkbFromMasterPage() As ImageButton
Get
Return imgButton
End Get
End Property

 content page code behind:

Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load, Me.Load
If Not IsPostBack Then

Dim cmp As MasterPage = CType(Master, MasterPage)
If Not IsNothing(cmp) Then
AddHandler cmp.lnkbFromMasterPage.Click, AddressOf lnkbFromMasterPage_Click
End If

End If
End Sub

Protected Sub lnkbFromMasterPage_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)

Response.Write("test")

End Sub

I'm not getting the message printed to the screen so I presume it isn't working correctly can anyone help? Thanks in advance.

Gemma

0
supergirl_gem
5/13/2008 7:58:13 AM
asp.net.navigation-controls 13714 articles. 0 followers. Follow

3 Replies
941 Views

Similar Articles

[PageSpeed] 13
Get it on Google Play
Get it on Apple App Store

Remove the IsNotPostBack so that the code runs on postback too, the event is triggered after the page load and if you haven't wired up the event after the postback the page doesn't know you're interested in it.


Softgear
http://www.softgear.se
http://mats.softgear.se
0
MatsL
5/13/2008 8:33:34 AM

thanks

0
supergirl_gem
5/13/2008 8:40:15 AM

No problems, happy I could help you out. Smile

 


Softgear
http://www.softgear.se
http://mats.softgear.se
0
MatsL
5/13/2008 8:51:54 AM
Reply: