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. Event handling in custom control

Event handling in custom control

Scheduled Pinned Locked Moved ASP.NET
helpsysadminquestion
3 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.
  • M Offline
    M Offline
    Mike Puddephat
    wrote on last edited by
    #1

    I hope someone can help with this problem. I have a custom control with a submit button on it. I simply want to wire up the OnClick event for the button, but it never seems to get called. I have checked all the documentation and I think I am doing everything correctly. But obviously something is wrong. In my custom control, I override CreateChildControls and add an OnClick function as follows: protected override void CreateChildControls() { Button btn = new Button(); btn.Text = "Submit"; btn.Click += new System.EventHandler(OnClick); Controls.Add(btn); } public void OnClick(object o, EventArgs e) { ... } And create the custom control in my web form as follows: <%@ Register TagPrefix="RI" Namespace="CustomControl" Assembly="CustomControl" %> ... <RI:WebCustomControl1 runat="server" ID="Webcustomcontrol11" NAME="Webcustomcontrol11" /> But OnClick never gets called. Can anyone help??????? I am totally at a loss as to why OnClick is not called. Many thanks!

    M 1 Reply Last reply
    0
    • M Mike Puddephat

      I hope someone can help with this problem. I have a custom control with a submit button on it. I simply want to wire up the OnClick event for the button, but it never seems to get called. I have checked all the documentation and I think I am doing everything correctly. But obviously something is wrong. In my custom control, I override CreateChildControls and add an OnClick function as follows: protected override void CreateChildControls() { Button btn = new Button(); btn.Text = "Submit"; btn.Click += new System.EventHandler(OnClick); Controls.Add(btn); } public void OnClick(object o, EventArgs e) { ... } And create the custom control in my web form as follows: <%@ Register TagPrefix="RI" Namespace="CustomControl" Assembly="CustomControl" %> ... <RI:WebCustomControl1 runat="server" ID="Webcustomcontrol11" NAME="Webcustomcontrol11" /> But OnClick never gets called. Can anyone help??????? I am totally at a loss as to why OnClick is not called. Many thanks!

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

      I'm not very sure but did you inherit your control from INamingContainer? Its is needed dor handling child control events. Mazy "And the carpet needs a haircut, and the spotlight looks like a prison break And the telephone's out of cigarettes, and the balcony is on the make And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits

      M 1 Reply Last reply
      0
      • M Mazdak

        I'm not very sure but did you inherit your control from INamingContainer? Its is needed dor handling child control events. Mazy "And the carpet needs a haircut, and the spotlight looks like a prison break And the telephone's out of cigarettes, and the balcony is on the make And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits

        M Offline
        M Offline
        Mike Puddephat
        wrote on last edited by
        #3

        Thanks very much, Mazdak. That was exactly my problem. I was not inheriting from INamingContainer. I didn't realise you had to. Mike.

        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