Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Bubble Event Implementation in UserControl

Bubble Event Implementation in UserControl

Scheduled Pinned Locked Moved ASP.NET
questionwinformshelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dsrao
    wrote on last edited by
    #1

    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

    Z M 2 Replies Last reply
    0
    • D dsrao

      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

      Z Offline
      Z Offline
      zhengdong jin
      wrote on last edited by
      #2

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

      D 1 Reply Last reply
      0
      • Z zhengdong jin

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

        D Offline
        D Offline
        dsrao
        wrote on last edited by
        #3

        Thank you for your help. I want implement this concept in UserControl. Thanks & Regards Rao

        1 Reply Last reply
        0
        • D dsrao

          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

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          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

          D 1 Reply Last reply
          0
          • M minhpc_bk

            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

            D Offline
            D Offline
            dsrao
            wrote on last edited by
            #5

            Thank you very much. Thanks & Regards Rao

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups