Bubble Event Implementation in UserControl
-
Hi, Can anybody help me.I don't have much knowledge on BubbleEvents I want implement BubbleEvent concept in User control.I have user control that contains A,B.. Z link buttons and place this usercontrol on webform.If i Click any linkbutton i want show that link button text value into webform label control.I don't want write 26 event handler i need only generic event handler that means 1 click event handler. Another question here. I have 2 usercontrols say FirstUC.ascx it contains textbox1 and button controls and SecondUC.ascx contains Lable control.I placed these usercontrols on webform.If i entered some value in textbox1 and click button of FirstUC.I want show that textbox1 value into lable control of secondUC How can i interact these user controls .Please let me know. Thanks & Regards Rao
-
Hi, Can anybody help me.I don't have much knowledge on BubbleEvents I want implement BubbleEvent concept in User control.I have user control that contains A,B.. Z link buttons and place this usercontrol on webform.If i Click any linkbutton i want show that link button text value into webform label control.I don't want write 26 event handler i need only generic event handler that means 1 click event handler. Another question here. I have 2 usercontrols say FirstUC.ascx it contains textbox1 and button controls and SecondUC.ascx contains Lable control.I placed these usercontrols on webform.If i entered some value in textbox1 and click button of FirstUC.I want show that textbox1 value into lable control of secondUC How can i interact these user controls .Please let me know. Thanks & Regards Rao
I had submited an article about a datagrid pager control in the source code you can find some useful hints. http://www.codeproject.com/useritems/DataGrid_Pager.asp[^] good luck ASP.NET C# VB VC & SQL Windows APP ...
-
I had submited an article about a datagrid pager control in the source code you can find some useful hints. http://www.codeproject.com/useritems/DataGrid_Pager.asp[^] good luck ASP.NET C# VB VC & SQL Windows APP ...
-
Hi, Can anybody help me.I don't have much knowledge on BubbleEvents I want implement BubbleEvent concept in User control.I have user control that contains A,B.. Z link buttons and place this usercontrol on webform.If i Click any linkbutton i want show that link button text value into webform label control.I don't want write 26 event handler i need only generic event handler that means 1 click event handler. Another question here. I have 2 usercontrols say FirstUC.ascx it contains textbox1 and button controls and SecondUC.ascx contains Lable control.I placed these usercontrols on webform.If i entered some value in textbox1 and click button of FirstUC.I want show that textbox1 value into lable control of secondUC How can i interact these user controls .Please let me know. Thanks & Regards Rao
Hi there, IMO, you simply add a new custom event to your user control, and you may also need to create a custom event argument class to pass the event data (the linkbutton's text) to the event handler when the custom event is raised. Here are the steps: + Create the custom event argument:
public class LinkButtonClickEventArgs : EventArgs
{
private string m_linkButtonText;public LinkButtonClickEventArgs(string linkButtonText) { m\_linkButtonText = linkButtonText; } public string LinkButtonText { get {return m\_linkButtonText;} }
}
+ Declare a custom delegate:
public delegate void LinkButtonClickEventHandler(object sender, LinkButtonClickEventArgs e);
+ Add a new custom event to the user control and create a method to raise the event:
public class WebUserControl1 : System.Web.UI.UserControl
{
public event LinkButtonClickEventHandler LinkButtonClick;protected virtual void OnLinkButtonClick(LinkButtonClickEventArgs e) { if(this.LinkButtonClick!=null) { this.LinkButtonClick(this, e); } }
}
+ To raise the event LinkButtonClick in the user control, you simply create an event handler for the click event of all the LinkButton controls in the user control, and in the handler you can provide some code to do that:
private void LinkButton_Click(object sender, System.EventArgs e)
{
LinkButton linkButton = sender as LinkButton;
LinkButtonClickEventArgs eventArgs = new LinkButtonClickEventArgs(linkButton.Text);
OnLinkButtonClick(eventArgs);
}In addition, you can also override the OnBubbleEvent method to bubble the click event of the LinkButton to the user control:
protected override bool OnBubbleEvent(object source, EventArgs args)
{
LinkButton sourceControl = source as LinkButton;
//The event is only bubbled up if the source control is an instance of the LinkButton type.
if(sourceControl != null)
{
LinkButtonClickEventArgs e = new LinkButtonClickEventArgs(sourceControl.Text);
OnLinkButtonClick(e);return true; } return false;
}
+ Now, in the web page, you simply subcribe the LinkButtonClick event of the user control, then can get the event data (the linkbutton's text) to assign to the label. There are a couple of ways which you can use to link the two user controls: you simply expose a public property in the FirstUC user control which holds an instance of the SecondUC control. You can find the SecondUC
-
Hi there, IMO, you simply add a new custom event to your user control, and you may also need to create a custom event argument class to pass the event data (the linkbutton's text) to the event handler when the custom event is raised. Here are the steps: + Create the custom event argument:
public class LinkButtonClickEventArgs : EventArgs
{
private string m_linkButtonText;public LinkButtonClickEventArgs(string linkButtonText) { m\_linkButtonText = linkButtonText; } public string LinkButtonText { get {return m\_linkButtonText;} }
}
+ Declare a custom delegate:
public delegate void LinkButtonClickEventHandler(object sender, LinkButtonClickEventArgs e);
+ Add a new custom event to the user control and create a method to raise the event:
public class WebUserControl1 : System.Web.UI.UserControl
{
public event LinkButtonClickEventHandler LinkButtonClick;protected virtual void OnLinkButtonClick(LinkButtonClickEventArgs e) { if(this.LinkButtonClick!=null) { this.LinkButtonClick(this, e); } }
}
+ To raise the event LinkButtonClick in the user control, you simply create an event handler for the click event of all the LinkButton controls in the user control, and in the handler you can provide some code to do that:
private void LinkButton_Click(object sender, System.EventArgs e)
{
LinkButton linkButton = sender as LinkButton;
LinkButtonClickEventArgs eventArgs = new LinkButtonClickEventArgs(linkButton.Text);
OnLinkButtonClick(eventArgs);
}In addition, you can also override the OnBubbleEvent method to bubble the click event of the LinkButton to the user control:
protected override bool OnBubbleEvent(object source, EventArgs args)
{
LinkButton sourceControl = source as LinkButton;
//The event is only bubbled up if the source control is an instance of the LinkButton type.
if(sourceControl != null)
{
LinkButtonClickEventArgs e = new LinkButtonClickEventArgs(sourceControl.Text);
OnLinkButtonClick(e);return true; } return false;
}
+ Now, in the web page, you simply subcribe the LinkButtonClick event of the user control, then can get the event data (the linkbutton's text) to assign to the label. There are a couple of ways which you can use to link the two user controls: you simply expose a public property in the FirstUC user control which holds an instance of the SecondUC control. You can find the SecondUC