Calling web form method from user control

S

Simon Harris

Hi All,

I am trying to call a method in a web form, from an event fired in a user
control. My user control displays a map, which has a link button to
enlarge/shrink the map. When the user enlarges the map, I want to hide my
navigation table etc, maximising the viewing area. I've been working on this
for 5 hours now, so far I have as detailed below - Which rund with out
error, but the final function never gets called. Any help/suggestions would
be appreciated.


Heres how far I have got:
==================

1) My user control is called map_display.ascx. This contains a link button,
onclick does the following, which is in map_display.ascx.vb:

Private Sub lbEnlarge_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lbEnlarge.Click
Dim evt As New EventArgs
Call MyEnlarge(e)
If Me.lbEnlarge.Text = "Shrink" Then
ChangeMapSize(pInitialMapSize)
Me.lbEnlarge.Text = "Enlarge"
Else
ChangeMapSize("700x350")
Me.lbEnlarge.Text = "Shrink"
End If
End Sub



2) 'MyEnlarge' is also within map_display.ascx.vb:
(Note public delegate and event lines, which I also added)

Public Delegate Sub EnlargeButtonHandler(ByVal sender As Object, ByVal e As
EventArgs)
Public Event EnlargeButton As EnlargeButtonHandler
Protected Sub MyEnlarge(ByVal e As EventArgs)
RaiseEvent EnlargeButton(Me, e)
End Sub



3) In my containing aspx page (Called map_and_property_info.aspx), the user
control is included like this:

<uc1:map_display id="Map_display1" runat="server"
onMyEnlarge="ToggleTblNavandInfo"></uc1:map_display>

The plan was to 'catch' the original event of the user clicking the link
button in the user control, then fire a function in the ASPX code behind -
Probably not relevent, but heres the function I wanted to eventually call.

Public Sub ToggleTblNavandInfo()
If Me.TblNavandInfo.Visible = False Then
Me.TblNavandInfo.Visible = True
Else
Me.TblNavandInfo.Visible = False
End If
End Sub
 
K

Karl Seguin

Shouldn't that be
onEnlargeButton
instead of
onMyEnlarge in the <uc1: control?

Karl
 
S

Simon Harris

Hi Karl,

I changed it to onEnlargeButton and I now get this error:

===============================
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30408: Method 'Public Sub ToggleTblNavandInfo()'
does not have the same signature as delegate 'Delegate Sub
EnlargeButtonHandler(sender As Object, e As System.EventArgs)'.

Source Error:


Line 87: </table>
Line 88: </td>
Line 89: <td><uc1:map_display id="Map_display1" runat="server"
onEnlargeButton="ToggleTblNavandInfo"></uc1:map_display></td>
Line 90: </tr>
Line 91: </table>


Source File: D:\introot\netapps\gis\map_and_property_info.aspx Line: 89

===============================
 
K

Karl Seguin

Simon,
I had noticed this but forgot to mention it, the ToggleTblNavandInfo
function has to have the same signature (return type and parameters) as your
delegate, in other words it needs to be:

Public Sub ToggleTblNavandInfo (sender As Object, e As System.EventArgs)


Karl
 
S

Simon Harris

Hi Karl,

Just changed my function as you suggested...IT WORKS!!! Woo Hoo!! (Calm down
man, calm down!) :)

I reasonably new to .Net...although it is working now, I dont know why -
Perhaps you could explain a little?

Thank you for your help.

Simon.
 
K

Karl Seguin

Simon:
Not sure what you don't understand. The delegate and function signature?
Deep down all of this is just function pointers...a function pointer allows
you to dynamically run a function. However, it only works when you know the
exact signature of the function (return type, parameter type). Delegates
are like function pointers...you dynamically invoke the function that's
hooked to the event, but it has to have the exact same signature as your
delegate

An event has a delegate type
only function which have the same signature as defined by the delegate type
can be hooked into the event...

Hope that helped :)

Karl
 

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

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top