By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,117 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,117 IT Pros & Developers. It's quick & easy.

adding event handler in user Control

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.