Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
User control question
Message
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Divers
Thread ID:
00696293
Message ID:
00697619
Vues:
13
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() ...
>
>
>
>Or, alternatively, do you recommend a different approach?
>
>Al
>
>>The code should be placed in the Click event of the Delete Button on your UserControl. That way when the button is clicked then the Page's function will be called. Here is the VB.NET translation:
>>
>>
>>CType(Me.Page, WebForm1).fnDeleteRecord()
>>
>>
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform