473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 22152
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.com

"VMI" <VM*@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.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.UserControl which exposes a
method called RaiseBubbleEvent. 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_SelectedIndexChanged(Object sender,EventArgs e)
{

CommandEventArgs ee = new CommandEventArgs("CountryChange", null);

RaiseBubbleEvent(sender, ee);
}

override protected bool OnBubbleEvent(object sender, System.EventArgs e)
{
bool isHandled = false;

if(e is CommandEventArgs)
{
CommandEventArgs ee = (CommandEventArgs)e;

switch(ee.CommandName)
{
case "CountryChange":
ddlStates.CountryCode = ddlCountries.SelectedCountry;
ddlStates.DataBind();
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 commandEventArgs to send custom events
to the OnBubbleEvent.
Change the name to "residentialAddress" or "PostalAddress" 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
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...
2
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...
2
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()...
4
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...
1
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...
9
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...
4
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...
1
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...

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.