Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Events in a custom template control

Reply
Thread Tools

Events in a custom template control

 
 
Matthew Judd
Guest
Posts: n/a
 
      08-06-2004
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
 
Reply With Quote
 
 
 
 
Dale
Guest
Posts: n/a
 
      08-08-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom control within a custom control J R M ASP .Net 2 06-01-2006 06:04 PM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
Capturing event from other custom control within another custom control Jonah Olsson ASP .Net 1 04-05-2005 01:39 PM
How do u wire up events to controls in a custom template control??? Chris Newby ASP .Net 1 02-28-2005 07:13 AM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM



Advertisments