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:
00696823
Vues:
11
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()
>Hi Cathi,
>
>I'm struggling a bit with this. I have two more questions if you don't mind:
>
>1. Where does this code get placed on the webform?
>
>2. Also, what is the equivalent VB code for this ...
>
>
>(WebForm1)this.Parent.Page).fnDeleteRecord();
>
>
>
>
>
>>You don't have to create an inherited class. The default for a new ASP.NET project is "WebForm1". What I was referring to was that you need to cast the Page object returned when you call the usercontrol's Page property to the actual page class that you are using (like WebForm1). If not, then you will get returned a generic Page object and not the WebForm1 class that contains your custom methods.
>>
>>>Hi Cathi,
>>>
>>>Thanks for the response. At this point I've created the commandbutton user control and now I just want to test it out in a webform - named 'webform1'. The form class, then is, 'webform1' (webform1.aspx.vb). I haven't created a form class at this time. (i.e. one from which all other forms in the project will inherit properties and methods).
>>>
>>>Are you suggesting that before I can get this to work I should first create a webform class? I'm a bit confused ...
>>>
>>>Thanks in advance for your assistance.
>>>
>>>Al
>>>
>>>>UserControls have a property called "Page" that is a reference to the page that contains the usercontrol. You could use that property to access the methods contained in the page object. One thing to keep in mind, you need to cast the page to the actual page class you are using like the following:
>>>>
>>>>
>>>>((MyPage)this.Parent.Page).fnDeleteRecord();
>>>>
>>>>
>>>>>Hi,
>>>>>
>>>>>For a new ASP.Net app we're building a number of web forms have the same basic functionality - that is - the ability to Add-Edit-Delete records. That being the case, I'd like to build a user control with the required command buttons that I'd just have to drop onto each web form.
>>>>>
>>>>>From the user control, I'd like to have it call a 'generic' function on each page. For example, when the Delete commandbutton is clicked, it should call the function 'fnDeleteRecord' on whichever web form is being used. So, my question is how do I tell the user control to call fnDeleteRecord on the web form?
>>>>>
>>>>>Or, am I way out in left field and is there a better way to do this ...
>>>>>
>>>>>Thanks, Al
-----------------------------------------

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