473,729 Members | 2,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

invoke methods on the parent page from the user control

Max
I want to do something like this in the user control:
Call myParentPage.Bi ndSQL()

BindSQL is a sub on the parent page. This user control will be used on
multiple pages. Perhaps this is not a good idea? This is why it is so
difficult?

-Max
Nov 18 '05 #1
3 3262
Max wrote:
I want to do something like this in the user control:
Call myParentPage.Bi ndSQL()

BindSQL is a sub on the parent page. This user control will be used on
multiple pages. Perhaps this is not a good idea? This is why it is so
difficult?

-Max

You have a .Page property in the user control, the only problem is you
need to cast it before calling that function....

((MyPageClass)t his.Page).BindS QL

But if you do this, you're tying your user control to one type of
containing page (which is usually one page). If you do it this way, I'd
pry create a superclass for all pages that share this function and then
cast to that type.....

The other way to do it (and is pry better from an OO encapsulation
standpoint) is to expose an event in the user control that it raises
when it wants to call the .Page's function. But instead of having to
know the page type, or function name, the user control lets the page be
responsible for registering an event handler/listener to that event when
it creates one of your user controls.

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #2
its trival, either use reflection to call the method:

MethodInfo mi = this.Page.GetTy pe().GetMethod( "BindSQL", BindingFlags.Pu blic
| BindingFlags.In stance);
if (mi) mi.Invoke(null, new Object[] {});

or have pages inherit from a base and cast:

myBasePage bp = this.Page as myBasePage;
if (bp) bp.BindSQL();

-- bruce (sqlwork.com)

"Max" <ma*****@portvi sta.com> wrote in message
news:DE******** **********@twis ter.tampabay.rr .com...
I want to do something like this in the user control:
Call myParentPage.Bi ndSQL()

BindSQL is a sub on the parent page. This user control will be used on
multiple pages. Perhaps this is not a good idea? This is why it is so
difficult?

-Max

Nov 18 '05 #3
Max
I don't understand how reflection will work. I understand it retrieves the
method from assembly, but I don't know how to use it in my case.

MethodInfo mi = Me.Page.GetType ().GetMethod("B indSQL", BindingFlags.Pu blic
....
and then you lost me...

Your casting example won't appear to work, because you're saying I need to
use the page's class, but I want to call this sub from a user control on
every page.
"bruce barker" <no***********@ safeco.com> wrote in message
news:%2******** **********@tk2m sftngp13.phx.gb l...
its trival, either use reflection to call the method:

MethodInfo mi = this.Page.GetTy pe().GetMethod( "BindSQL", BindingFlags.Pu blic | BindingFlags.In stance);
if (mi) mi.Invoke(null, new Object[] {});

or have pages inherit from a base and cast:

myBasePage bp = this.Page as myBasePage;
if (bp) bp.BindSQL();

-- bruce (sqlwork.com)

"Max" <ma*****@portvi sta.com> wrote in message
news:DE******** **********@twis ter.tampabay.rr .com...
I want to do something like this in the user control:
Call myParentPage.Bi ndSQL()

BindSQL is a sub on the parent page. This user control will be used on
multiple pages. Perhaps this is not a good idea? This is why it is so
difficult?

-Max


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2024
by: Charles Law | last post by:
I have a user control created on the main thread. Let's say, for arguments sake, that it has a single property that maintains a private variable. If I want to set that property from a worker thread, do I need to use UserControl1.Invoke to set it, or can I just set it? After all, it is only changing a private variable. TIA Charles
5
1805
by: Jim | last post by:
I have a user control that has two nested user controls within it. I have a method in the parent called CloseDetailsMaint, and I need to be able to call it from one of the child user controls that is nested within the parent. How do I do this?
5
7666
by: Steve Richter | last post by:
In my user control I want to read the ViewState dictionary of the Parent control. But this sensible idea is not permitted by the compiler: Compiler Error Message: CS1540: Cannot access protected member 'System.Web.UI.Control.ViewState' via a qualifier of type 'System.Web.UI.Control'; the qualifier must be of type 'ASP.ItemOrderGrid' (or derived from it) Source Error:
0
2961
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode thread. so far so good. all contacts r added properly. now when another login adds me in his contact, i recv a subscription, so i popup a form and ask for accept/reject. this all happens in a separate thread. popup form gets opened and choice is...
1
11431
by: David Lozzi | last post by:
Hello, I have a user control that saves data. When the data is saved, I need to call a function in the parent page from the user control to initiate something else. I know I can set it up so that the save button is in the parent page and calls the save function of the user control and then whatever I need from the parent page, but I'd rather keep the save button in the user control as I am going to be using the same control elsewhere. ...
15
62089
by: Oleg Subachev | last post by:
I need to programmatically invoke from other class Click event of the Button on my Form. Button.OnClick method is protected, not public. How to perform this ? Oleg Subachev
11
11257
by: cindy | last post by:
I have a form, has javascript registered so a modal pops up. Button click will close form. Now I need to do an update with modal form data before it closes. I can put a second button and register the onclick attribute of the second button to the javascript to close the form after user clicks upload button click upload do the update to database then programmatically click the second button the use on onclick attribute that sees the...
5
2343
by: Josh Nikle | last post by:
I have a webform containing a GridView control "GridView1" and usercontrol which is also a GridView "GridView2." I have a button column in the usercontrol. The code behind that button adds an entry to my database, which it's doing fine, but I can't get GridView1 to show the updated data unless I browse to another page and then come back. I've been reading about using java script to accomplish this, but I must be doing something wrong....
5
2183
by: gnewsgroup | last post by:
In my user control, I would like to find a Label control in the parent page (the page that uses my user control). I need to update that Label.Text when something happens in the user control. I don't want to go through the hassle of creating events in the user control, and then let the parent handle the event. What is the easiest way to find a control in the parent page? Right now, I am simply manually traversing it from the user...
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.