Professional Web Applications Themes

Events in a custom template control - ASP.NET Building Controls

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

  1. #1

    Default Events in a custom template control

    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 Guest

  2. #2

    Default Re: Events in a custom template control

    Implement the IPostBackEventHandler in your control. The framework
    doentation 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" <MatthewJudddiscussions.microsoft.com> wrote in message
    news:5753FEEC-C728-4257-B6DC-0D807C991852microsoft.com...
    > 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 Guest

Similar Threads

  1. Order of events called in a custom control
    By Eddie Chan in forum ASP.NET Building Controls
    Replies: 1
    Last Post: January 28th, 12:45 PM
  2. how to add events to a custom control
    By John Saunders in forum ASP.NET Building Controls
    Replies: 0
    Last Post: July 24th, 11:18 PM
  3. Custom Server Control Events
    By Chris Kennedy in forum ASP.NET Building Controls
    Replies: 0
    Last Post: April 6th, 08:56 PM
  4. add events to dropdown list in custom server control
    By ton in forum ASP.NET Building Controls
    Replies: 3
    Last Post: February 6th, 12:29 AM
  5. Events for a custom server control
    By John Saunders in forum ASP.NET General
    Replies: 0
    Last Post: August 8th, 05:52 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139