Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
User control question
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00696293
Message ID:
00697746
Views:
15
Thank-you very much for your assistance.

>There are two approaches you can use.
>
>1. Create a parent class that has the generic method contained in it. Base the actual web pages on the parent class (using the Inherits keyword when the class is defined) like below:
>
>
>Public Class WebForm1
>    Inherits MyBaseWebForm
>
>
>Then when you use CType in the button click event, you will cast to the parent's class name since it contains the method you want to run.
>
>
>CType(Me.Page, MyBaseWebForm).fnDeleteRecord()
>
>
>
>2. The other approach is to use reflection. You will want to use this method if you will be overriding the method in each class instance. It is not as efficient as the approach above but is necessary if you need it. At the top of the user control code file type:
>
>
>Imports System.Reflection
>
>
>In the button's click event you would type:
>
>
>Dim myMethodInfo As MethodInfo = Page.GetType().GetMethod("fnDeleteRecord")
>myMethodInfo.Invoke(Page, Nothing)
>
>
>This will call the actual method contained in WebForm1 or WebForm2, etc.
>
>>This works - thanks Cathi. Next question: I'll be running this event in the click event of commandbuttons on a user control. This user control will appear on numerous pages (i.e. - not just 'WebForm1'). Is there an easy way to determine which aspx page the control is currently residing in? Or, should I use some type of session variable to store this info?
>>
>>Because, depending on the current web form, the code could be:
>>
>>
>>CType(Me.Page, WebForm1).fnDeleteRecord()
>>CType(Me.Page, WebForm2).fnDeleteRecord()
>>CType(Me.Page, WebForm3).fnDeleteRecord() ...
>>
>>
>>
Al Williams

Anola MB, CANADA
Previous
Reply
Map
View

Click here to load this message in the networking platform