473,837 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User Control and Page Events

Ok...I've been looking for an answer to this problem and can't seem to find
one...Framework 1.1 mind you.

I have a base class that inherits from UserControl. I have 5 and soon to be
12 user controls that derive from this base class that represent US States
with appropriate business logic and rules. Inside the base class is an event
that is raised whenever you click a checkbox in the datagrid of each of the
user controls...no biggie... This event is to be seen by the page so that it
can take appropriate action upon handling the event (such as disabling
selections, etc...) however the page cannot see this event to handle it.

Now another event needs to be fired by the page when you make a selection in
one or more dropdowns that are then handled by each of the user controls as
appropriate. For example, if one dropdown value gets selected, each state
user control will compare its business rules to the selection and uncheck a
checkbox in its grid if the rules dictate. However, this event is never seen
by the control.

My problem is that I don't know where to define these events so that the
page and the controls can see and use them. The UC event i've defined in the
baseclass so that all the derived controls can access it through a protected
method. However, I cannot construct a handles on the page because the page
can't see it. Likewise I cannot construct a handles in the controls because
they cannot see the page event.

Any ideas or need for further info?
Mar 14 '07 #1
3 1445
>Likewise I cannot construct a handles in the controls because
>they cannot see the page event.
Any ideas or need for further info?
What about this idea:

1. You define a Notification List (NL) on the page for each event you need
to handle (or one list for all events):

public ArrayList NotificationLis t = new ArrayList();

2. Each UC has one base class, wich in its OnLoad method registers itself in
the NL:

public class MyBaseControl: UserControl
{
override OnLoad()
{
if (Page != null) (Page as MyBasePage).Not ificationList.A dd(this);
}

public HandlePageEvent (EventArgs e)
{
DoSomething();
}
}

3. When you have an event on a page, you do something like this:

protected MyList_Selected IndexChanged(Ev entArgs e)
{
foreach (MyBaseControl control in NotificationLis t)
control.HandleP ageEvent(e);
}

So, all your UC will see the page's events.

PS. I typed directly into this window, so, it is a "psevdocode ".
Mar 14 '07 #2
That is what I wanted to avoid actually. But it may be the only way I can
achieve what I want to do. I do similar stuff elsewhere but it doesn't seem
as elegant as just doing it all with events and not making methods that
iterate over all the controls when each control could just subscribe the the
event as needed.

I would rather do this with pure events. It seems that if you don't derive
from a base class then event handling is 1:1. However, as soon as I started
deriving then the whole event model blew up because nothing can see the
other's events. Which seems counterintuitiv e.

Thanks for the input - any other ideas?

"Sergey Gorbachev" wrote:
Likewise I cannot construct a handles in the controls because
they cannot see the page event.
Any ideas or need for further info?

What about this idea:

1. You define a Notification List (NL) on the page for each event you need
to handle (or one list for all events):

public ArrayList NotificationLis t = new ArrayList();

2. Each UC has one base class, wich in its OnLoad method registers itself in
the NL:

public class MyBaseControl: UserControl
{
override OnLoad()
{
if (Page != null) (Page as MyBasePage).Not ificationList.A dd(this);
}

public HandlePageEvent (EventArgs e)
{
DoSomething();
}
}

3. When you have an event on a page, you do something like this:

protected MyList_Selected IndexChanged(Ev entArgs e)
{
foreach (MyBaseControl control in NotificationLis t)
control.HandleP ageEvent(e);
}

So, all your UC will see the page's events.

PS. I typed directly into this window, so, it is a "psevdocode ".
Mar 15 '07 #3
Thanks for the input - any other ideas?

Maybe the UC can add their own event handlers to the Page's controls?
Something like this:

public class MyBaseControl: UserControl
{
override OnInit()
{
base.OnInit();

if (Page != null) (Page.MyList.Se lectedIndexChan ged += new
EventHandler(My List_SelectionC hanged);
}

void MyList_Selectio nChanged(object sender, EventArgs e)
{
DoSomething();
}
}
Mar 15 '07 #4

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

Similar topics

1
7595
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
1
8187
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the first time the control is dynamically loaded, everything works fine. After that, if the control is loaded again from the page button event handler, the user controls events fail to fire on the first click NOTE: I (believe I) am rebuilding all...
10
2514
by: George G. | last post by:
Hi there, I am busy writing a new asp.net application and I am reusing some of my existing asp functions and methods in a user control. I need access to session, request and response in some of the functions and I can't find out how to do it. Here is an example of what I do and I get the following Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the...
6
12290
by: grist2mill | last post by:
I want to create a standard tool bar that appears on all pages that is a control. The toolbar has a button 'New'. What I wolud like when the user clicks on 'New' depends on the page they are on. I would like to do this by defining a NewFunc() that is different in each (code-behind) page which is called by the standard 'New' button in the toolbar. How can I get this to work? So far I have the following (which doesnt work). When the user...
4
1759
by: thomson | last post by:
Hi all, i do have a user control with 4 buttons, and all the events are firing properly, My problem is that i need to right an event handler in the user control, which gets fired after a specific process is done,, but the form which will host the user control has to specify what has to be done Something like this , if the event is fired it should call the event in
4
2523
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once I have exposed a public property containing the value of a textbox in a user control..how do I grab this from the calling page? I cant think of the syntax, since my page doesnt know the contents of the class (and therefore, the public...
8
3195
by: mark.norgate | last post by:
I've run into a few problems trying to use generics for user controls (classes derived from UserControl). I'm using the Web Application model rather than the Web Site model. The first problem I'm having is that the partial class signature in my projectDetails.ascx.cs file looks like this: public partial class ProjectDetailsControl<TEntryServiceProvider: UserControl, INamingContainer where TEntryServiceProvider : IEntryServiceProvider...
9
3205
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will load with different data (locations, departments, etc.).
2
4833
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be required: <%@ Register TagPrefix="UC" TagName="MyUserCtrl" Src="MyUC.ascx" %> Assuming that the ASPX page doesn't use a code-behind, I can access the properties, events etc. of the user control in the ASPX page in this way (assume that the ASPX page...
2
15083
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have been able to find the cause of the problem, and will describe it here first textually and then through a code example. The purpose of what I am trying to do is to create a postback-free web application through the use of ASP.net AJAX UpdatePanels...
0
9843
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
9682
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
10575
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...
0
10275
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9406
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...
0
7004
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();...
0
5850
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4475
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4043
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.