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. user control button click event

user control button click event

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
2 Posts 2 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.
  • S Offline
    S Offline
    satyav
    wrote on last edited by
    #1

    we have a user control(it has one textbox and button),few text boxes and another button on a form.How to control the button click event? Thanks in advance Vani

    M 1 Reply Last reply
    0
    • S satyav

      we have a user control(it has one textbox and button),few text boxes and another button on a form.How to control the button click event? Thanks in advance Vani

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

      I think there is nothing to say how to control the click event of a button on a form as you might already know that thing. And to control that event of the button on your user control, you simply define events in your control to respond to user actions on the Web form. You can get through the following steps: 1. Declare the event whithin your user control:

      public event EventHandler Click;

      2. Create a method to raise the event.

      protected virtual void OnClick(EventArgs e)
      {
      if(Click != null)
      {
      Click(this, e);
      }
      }

      3. Raise the event from within your user control's code: (say, Button1 on your control)

      private void Button1_Click(object sender, System.EventArgs e)
      {
      //You can do something here then call the OnClick method.
      OnClick(e);
      }

      4. To use the control Click event, you simply add the user control on a Web form, then write a handler that responds to the event:

      private void UserControl1_Click(object sender, System.EventArgs e)
      {
      //Your code here to repond to the user Click event.
      }

      For more information, see Events in ASP.NET Server Controls[^] in MSDN.

      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