Events in a custom template control

Discussion in 'ASP .Net Building Controls' started by Matthew Judd, Aug 6, 2004.

  1. Matthew Judd

    Matthew Judd Guest

    I have written a template control which contains a button. I have added a
    public event to the control which I raise on the button's Click event. In the
    main page that contains an instance of this template control I have code in
    the codebehind page to handle this event. My problem is that this code never
    fires and in fact the form validation controls don't respond when I click the
    button either. Here are some code snippets:

    -This is the start of my template control:

    <ToolboxData("<{0}:TableTemplate runat=server></{0}:TableTemplate>")> Public
    Class TableTemplate
    Inherits System.Web.UI.WebControls.WebControl
    Implements INamingContainer

    Public Event Submit(ByVal Sender As Object, ByVal e As System.EventArgs)
    Private WithEvents m_Submit As New Button

    Private Sub m_Submit_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles m_Submit.Click
    RaiseEvent Submit(Me, EventArgs.Empty)
    End Sub


    - Then in the code behind of my containing page:

    Public Class NewProject
    Inherits System.Web.UI.Page

    Protected WithEvents TableTemplate1 As TableTemplate.TableTemplate

    Private Sub TableTemplate1_Submit(ByVal Sender As Object, ByVal e As
    System.EventArgs) Handles TableTemplate1.Submit
    Response.Write("Clicked")
    Response.End
    End Sub

    ---
    I have tried this several different ways and I have not been able to get
    this to work. Does anybody have any idea what I am doing wrong?

    Thanks.

    Matthew Judd
    Matthew Judd, Aug 6, 2004
    #1
    1. Advertising

  2. Matthew Judd

    Dale Guest

    Implement the IPostBackEventHandler in your control. The framework
    documentation has a great example showing the implementation as well as
    creating the necessary event which you can then handle in your control
    and/or in your page.

    Hope that helps,

    Dale Preston
    MCAD, MCSE, MCDBA

    "Matthew Judd" <> wrote in message
    news:...
    > I have written a template control which contains a button. I have added a
    > public event to the control which I raise on the button's Click event. In

    the
    > main page that contains an instance of this template control I have code

    in
    > the codebehind page to handle this event. My problem is that this code

    never
    > fires and in fact the form validation controls don't respond when I click

    the
    > button either. Here are some code snippets:
    >
    > -This is the start of my template control:
    >
    > <ToolboxData("<{0}:TableTemplate runat=server></{0}:TableTemplate>")>

    Public
    > Class TableTemplate
    > Inherits System.Web.UI.WebControls.WebControl
    > Implements INamingContainer
    >
    > Public Event Submit(ByVal Sender As Object, ByVal e As

    System.EventArgs)
    > Private WithEvents m_Submit As New Button
    >
    > Private Sub m_Submit_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles m_Submit.Click
    > RaiseEvent Submit(Me, EventArgs.Empty)
    > End Sub
    >
    >
    > - Then in the code behind of my containing page:
    >
    > Public Class NewProject
    > Inherits System.Web.UI.Page
    >
    > Protected WithEvents TableTemplate1 As TableTemplate.TableTemplate
    >
    > Private Sub TableTemplate1_Submit(ByVal Sender As Object, ByVal e As
    > System.EventArgs) Handles TableTemplate1.Submit
    > Response.Write("Clicked")
    > Response.End
    > End Sub
    >
    > ---
    > I have tried this several different ways and I have not been able to get
    > this to work. Does anybody have any idea what I am doing wrong?
    >
    > Thanks.
    >
    > Matthew Judd
    Dale, Aug 8, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Newby
    Replies:
    1
    Views:
    597
    =?Utf-8?B?c2FyYQ==?=
    Feb 28, 2005
  2. Jonah Olsson
    Replies:
    1
    Views:
    571
    Scott Allen
    Apr 5, 2005
  3. J R M
    Replies:
    2
    Views:
    430
    Charlie@CBFC
    Jun 1, 2006
  4. Matt Sokol
    Replies:
    2
    Views:
    378
    Theo Tillotson
    Aug 7, 2003
  5. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    354
    Chris
    Aug 30, 2005
Loading...

Share This Page