Events in a custom template control

M

Matthew Judd

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
 
D

Dale

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top