473,586 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding event handler in user Control

VMI
My aspx has a user Control (a .ascx) that includes all the fields of an
address (add1, city, st, etc...). How can I add an event handler to a
comboBox inside the .ascx from within my aspx page? I just want to add this
event handler to that instance of the comboBox.

Thanks.
May 17 '06 #1
4 22182
VMI,

In order to do this, the control has to either expose the combo box
publically as a property (at which point, you can wire up an event), or it
would have to expose an event from the combobox, and aggregate the event
itself so that the page can connect to it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"VMI" <VM*@discussion s.microsoft.com > wrote in message
news:5B******** *************** ***********@mic rosoft.com...
My aspx has a user Control (a .ascx) that includes all the fields of an
address (add1, city, st, etc...). How can I add an event handler to a
comboBox inside the .ascx from within my aspx page? I just want to add
this
event handler to that instance of the comboBox.

Thanks.

May 17 '06 #2
Every user control inherits from System.Web.UI.U serControl which exposes a
method called RaiseBubbleEven t. You do not necessarily have to make your
controls public. You can just call this method from your user control and
have the hosting page or control handle it through the protected method
OnBubbleEvent. Below is some example code where you can raise an event from a
custom dropdownlist control and the handle the event in the hosting page.

/// <summary>
/// Raises a custom event to the user of the control
/// if you want to sync this control with another.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ddCountries_Sel ectedIndexChang ed(Object sender,EventArg s e)
{

CommandEventArg s ee = new CommandEventArg s("CountryChang e", null);

RaiseBubbleEven t(sender, ee);
}

override protected bool OnBubbleEvent(o bject sender, System.EventArg s e)
{
bool isHandled = false;

if(e is CommandEventArg s)
{
CommandEventArg s ee = (CommandEventAr gs)e;

switch(ee.Comma ndName)
{
case "CountryChange" :
ddlStates.Count ryCode = ddlCountries.Se lectedCountry;
ddlStates.DataB ind();
isHandled = true;
break;

}
}

return isHandled;
}

You can find lots of documentation on this in msdn help

smc750
http://www.certdev.com

VMI wrote:
My aspx has a user Control (a .ascx) that includes all the fields of an
address (add1, city, st, etc...). How can I add an event handler to a
comboBox inside the .ascx from within my aspx page? I just want to add this
event handler to that instance of the comboBox.

Thanks.


--
Message posted via http://www.dotnetmonster.com
May 17 '06 #3
VMI
I tried both version but I opted to use RaisedBubble and OnBubbleEvent to fix
the problem.
The only problem I'm having because of this (if you can call it a problem)
is that this aspx uses two instances of the same user control (the
residential address and the Postal address). How can I distinguish between
them? For example, how can I check in OnBubbleEvent to check the comboBox in
the Postal "version" of the user control (instead of the Residential User
Control)?

Thanks again.

"VMI" wrote:
My aspx has a user Control (a .ascx) that includes all the fields of an
address (add1, city, st, etc...). How can I add an event handler to a
comboBox inside the .ascx from within my aspx page? I just want to add this
event handler to that instance of the comboBox.

Thanks.

May 17 '06 #4
The code shows how you can change the commandEventArg s to send custom events
to the OnBubbleEvent.
Change the name to "residentialAdd ress" or "PostalAddr ess" and handle it
differently in the case statement.

smc750
http://www.certdev.com

VMI wrote:
I tried both version but I opted to use RaisedBubble and OnBubbleEvent to fix
the problem.
The only problem I'm having because of this (if you can call it a problem)
is that this aspx uses two instances of the same user control (the
residential address and the Postal address). How can I distinguish between
them? For example, how can I check in OnBubbleEvent to check the comboBox in
the Postal "version" of the user control (instead of the Residential User
Control)?

Thanks again.
My aspx has a user Control (a .ascx) that includes all the fields of an
address (add1, city, st, etc...). How can I add an event handler to a
comboBox inside the .ascx from within my aspx page? I just want to add this
event handler to that instance of the comboBox.

Thanks.


--
smc750
www.certdev.com

Message posted via http://www.dotnetmonster.com
May 19 '06 #5

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

Similar topics

3
4866
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
2
2102
by: Tim Marsden | last post by:
Hi, This is what I am doing, please comment if this is the correct way. I need to add controls to a form dynamically. Within the Page_Load event (is not Postback) I run a routine to create the controls, and populate the dropdowns etc, I use addhandler to define delegates to capture events raised by the controls. I store these controls...
2
2029
by: Sam Kuehn | last post by:
There has been a lot of articles on how to load user controls at runtime in the Init() method. UserControl myControl = (UserControl)LoadControl(stringControl); I add the control in the Init() method so that the viewstate to works properly. What if I want to let the user select what control to display? For instance say I have a drop down list of...
4
3132
by: PK9 | last post by:
I have a button at the top of my page that I have an onClick event handler for which makes some new controls (at the bottom of my page) visible. When the user clicks the button I make the new controls visible in the onclick event handler, but I do not know how to bring the focus to the bottom section of the page. So basically, when the user...
1
5240
by: David Veeneman | last post by:
I am writing a control that relies on its host to validate the contents of one of its fields. The control fires a custom 'FooNeedsValidating' event and passes the field's data with the event. The host handles the event, validates the data and returns the validation results to the control by a callback to a control method, SetFooError(). All of...
9
2460
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the post event will always execuate after the system is completed... - I want to wrap this functionality in a framework, so I could possibly have 3 or 4...
4
1661
by: Duncan Dimech | last post by:
Dear All I am writing a tool which requires to have controls added to it dynamically. To make the task more complex, the addition of the control cannot happen anywhere but it has to be instead of a token example <pthis is a test <textbox /and a text box should be entered </P> the tool should render the message and instead of <textbox...
1
2457
by: The Eclectic Electric | last post by:
I'd be very grateful if anyone could help me with this. From my limited knowledge of Javascript I don't think it is possible, but I'll punt anyway. I downloaded and very slightly adapted this guy's Javascript "combo box" - http://sandy.mcarthur.org/javascript/select/select.html. It allows my users (when I get some!) to select from a list of...
2
7652
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the PasswordRecovery with a Password reset required; a temporary password is sent to the account on file. I want an extra layer of security to accommodate...
0
7915
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...
0
8339
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...
0
8220
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...
1
5712
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...
0
5392
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...
0
3838
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...
0
3869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
1
1452
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.