473,769 Members | 5,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User control Click Event handling

I build user control, consists of different things (e.g label, image, etc.)
I want to handle click (and other) events, however I can not do it until I
do not assign event handler for each control inside me user contol. Is there
way to do this "smart" just inherit all possible events from usercontrol
class instead of rewriting custom handlers for each control inside ???

Thankx
Nov 15 '05 #1
2 29075
you mean you dont want to write event handler for label
control in side your control, however if some one clicks
on label you should get the click event out of your
control ...

Till some one tells you the real solution, i have a
suggestion to reduce little bit of your pain, write a
macro to write the event handler for your controls,
because all the controls click event can call your one
click event so there is hardly any change in the code
from one control to other controls click event ...

public delegate void MyClick (object
sender, System.EventArg s e);
public event MyClick cClick ;

private void UserControl1_Cl ick(object
sender, System.EventArg s e)
{
if (cClick != null)
cClick (sender,e);
}

private void label1_Click(ob ject sender,
System.EventArg s e)
{
UserControl1_Cl ick( sender, e);
}

private void label2_Click(ob ject sender, System.EventArg s
e)
{
UserControl1_Cl ick( sender, e);
}

Let me know if i should go into how to write a macro
which will take your control name and expand it in to a
click event hadler function ..

Sarosh
-----Original Message-----
I build user control, consists of different things (e.g label, image, etc.)I want to handle click (and other) events, however I can not do it until Ido not assign event handler for each control inside me user contol. Is thereway to do this "smart" just inherit all possible events from usercontrolclass instead of rewriting custom handlers for each control inside ???
Thankx
.

Nov 15 '05 #2
Here's a concept I've used before. Since you don't say how you're
showing your image, I'm using PictureBox in the example, but it can be
adapted to any control.

this.label1.Cli ck += new System.EventHan dler(this.PassT hrough_Click);
this.pictureBox 1.Click += new System.EventHan dler(this.PassT hrough_Click);
// etc.

// Click of label and picture box are sent to control
private void PassThrough_Cli ck(object sender, System.EventArg s e)
{
this.OnClick( e );
}

Chris R.

"Tamir Khason" <ta**********@t con-NOSPAM.co.il> wrote in message
news:e$******** *****@tk2msftng p13.phx.gbl...
I build user control, consists of different things (e.g label, image, etc.) I want to handle click (and other) events, however I can not do it until I
do not assign event handler for each control inside me user contol. Is there way to do this "smart" just inherit all possible events from usercontrol
class instead of rewriting custom handlers for each control inside ???

Thankx

Nov 15 '05 #3

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

Similar topics

1
7587
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
5
9751
by: George Durzi | last post by:
I have a simple user control with a text box and a submit button. When the user enters some text into the textbox and clicks the submit button, a record is created in the database. I'm using this user control inside another webform. The webform has a "Next" button which is initially disabled. When the user control successfully adds a record I want the Next button on the webform to get enabled. Checking if the record was added...
9
2337
by: Sridhar | last post by:
Hi, I have created a web page which includes a place holder. I also have a dropdown list in that webpage. when I select one of the choices in that dropdown list, It will load a user control into the place holder. This is done dynamically based on the choice they selected. This user control has a datagrid in it that supports paging. When I click on the next or prev buttons of the datagrid in a user control it should display the next page...
5
1400
by: Paul Bromley | last post by:
For some time now I have been struggling trying to understand how to handle events originating in a User Control that I have designed when using this in an application. Basically I need to respond to button clicks in my user control. I have struggled trying to understand Delegates, aqnd m still struggling. I then came across the following tutorial on MSDN and thought I had 'cracked it' ...
3
1561
by: c676228 | last post by:
Hi all, I have an event in user control email to handling email change when user want to change the input for email address. Here it is In email.ascx.vb: Protected Sub UpdateEmail(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtEmail.TextChanged If Session("Email") <> Me.Email Then Session("Email") = TxtEmail.Text 'or me.email End If End Sub
9
3191
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.).
3
1471
by: Toty Santana | last post by:
I need to make a new user control; it will contain a button and a drop down list. Can I make the button click event handling editable by the user, like he can specify the method that will handle this click event on the hosting page?
2
1824
by: RSH | last post by:
Hi, I have been trying to follow a tutorial on raising an event from a user control and then handling it in the parent page. The article is a little vague so I believe I have the code in place, but I cant seem to get it to work. Here is what I have:
1
2917
by: Efi Merdler | last post by:
Hi, I created a user control, but instead of handling exception in the user control level I prefer to handle them in the containing form. In the load event of the containing form I'm using: entryWindow.Error += new EventHandler(Page_Error); when entryWindow is my user control. Two questions:
0
9589
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
10211
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
10045
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
9994
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,...
1
7409
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
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.