How do I capture an event from a control inside a container?

K

Ken Sturgeon

I have a button inside a panel control. Apparently I can't expect VB to
respond to the button's _Click event. How do I capture the click event?

Thanks
Ken
 
A

Anthony Merante

You should be able to. You'd capture the event the same as if the button was
not in the panel.

You most likely have something else going on in the page life cycle thats
causing you to lose the click event.

-Tony
 
K

Ken Sturgeon

I hope it's as easy as you say Tony but when I run in debug mode it won't even compile. The code for the button click event follows.

Protected Sub btnAddEvent_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddEvent.Click
handleAddEventButton()
End Sub

I get the following error:

error BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Thanks for your help. I do appreciate it.
 
A

Anthony Merante

Hmm Im not a VB guy but have you declared btnAddEvent like:
Protected WithEvents btnAddEvent As System.Web.UI.WebControls.Button ?





I hope it's as easy as you say Tony but when I run in debug mode it won't even compile. The code for the button click event follows.

Protected Sub btnAddEvent_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddEvent.Click
handleAddEventButton()
End Sub

I get the following error:

error BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Thanks for your help. I do appreciate it.
 
K

Ken Sturgeon

Yes, I found a couple threads that indicated that as the solution to the error message I'm getting. When I added it I got the blue squiggly; when I hover over it it says...

btnAddEvent is already declared as 'Protected Dim WithEvents btnAddEvent As System.Web.UI.WebControls.Button' in this class

I don't see it declared anywhere else in the class. The only place it's referenced is in the aspx page where I created it.

<asp:panel ID="pnlAddEvent" runat="server" Width="100%" Direction="LeftToRight" Visible="False">
<hr />
<table>
<tr>
<td colspan="2" class="TableHeader"><font class="TableHeaderFont">Add Event</font></td>
</tr>
<tr>
<td><asp:HiddenField ID="hidNewEventID" runat="server" Value="" />
<asp:Label ID="lblNewEventDate" runat="server">Date:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventDate" runat="server" /></td>
</tr>
<tr>
<td><asp:Label ID="lblNewEventTitle" runat="server">Title:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventTitle" Width="200" MaxLength="60" runat="server" /></td>
</tr>
<tr>
<td><asp:Label ID="lblNewEventDesc" runat="server">Description:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventDesc" Width="200" MaxLength="60" runat="server" /></td>
</tr>
<tr>
<td colspan="2" align="right"><br /><asp:Button ID="btnAddEvent" runat="server" text="Add Event" /></td>
</tr>
</table>
</asp:panel>
Hmm Im not a VB guy but have you declared btnAddEvent like:
Protected WithEvents btnAddEvent As System.Web.UI.WebControls.Button ?





I hope it's as easy as you say Tony but when I run in debug mode it won't even compile. The code for the button click event follows.

Protected Sub btnAddEvent_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddEvent.Click
handleAddEventButton()
End Sub

I get the following error:

error BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Thanks for your help. I do appreciate it.
 
A

Anthony Merante

Do a Find and see if there is another button hidden in a region er something.
Yes, I found a couple threads that indicated that as the solution to the error message I'm getting. When I added it I got the blue squiggly; when I hover over it it says...

btnAddEvent is already declared as 'Protected Dim WithEvents btnAddEvent As System.Web.UI.WebControls.Button' in this class

I don't see it declared anywhere else in the class. The only place it's referenced is in the aspx page where I created it.

<asp:panel ID="pnlAddEvent" runat="server" Width="100%" Direction="LeftToRight" Visible="False">
<hr />
<table>
<tr>
<td colspan="2" class="TableHeader"><font class="TableHeaderFont">Add Event</font></td>
</tr>
<tr>
<td><asp:HiddenField ID="hidNewEventID" runat="server" Value="" />
<asp:Label ID="lblNewEventDate" runat="server">Date:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventDate" runat="server" /></td>
</tr>
<tr>
<td><asp:Label ID="lblNewEventTitle" runat="server">Title:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventTitle" Width="200" MaxLength="60" runat="server" /></td>
</tr>
<tr>
<td><asp:Label ID="lblNewEventDesc" runat="server">Description:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventDesc" Width="200" MaxLength="60" runat="server" /></td>
</tr>
<tr>
<td colspan="2" align="right"><br /><asp:Button ID="btnAddEvent" runat="server" text="Add Event" /></td>
</tr>
</table>
</asp:panel>
Hmm Im not a VB guy but have you declared btnAddEvent like:
Protected WithEvents btnAddEvent As System.Web.UI.WebControls.Button ?





I hope it's as easy as you say Tony but when I run in debug mode it won't even compile. The code for the button click event follows.

Protected Sub btnAddEvent_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddEvent.Click
handleAddEventButton()
End Sub

I get the following error:

error BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Thanks for your help. I do appreciate it.
 
K

Ken Sturgeon

No sir, "btnAddEvent" shows up once in the aspx as shown below and twice in the aspx.vb...

Protected WithEvents btnAddEvent As System.Web.UI.WebControls.Button
Protected Sub btnAddEvent_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddEvent.Click
...
End Sub

I really do appreciate your help on this. I'm pretty much at my wits end with the issue.

Do a Find and see if there is another button hidden in a region er something.
Yes, I found a couple threads that indicated that as the solution to the error message I'm getting. When I added it I got the blue squiggly; when I hover over it it says...

btnAddEvent is already declared as 'Protected Dim WithEvents btnAddEvent As System.Web.UI.WebControls.Button' in this class

I don't see it declared anywhere else in the class. The only place it's referenced is in the aspx page where I created it.

<asp:panel ID="pnlAddEvent" runat="server" Width="100%" Direction="LeftToRight" Visible="False">
<hr />
<table>
<tr>
<td colspan="2" class="TableHeader"><font class="TableHeaderFont">Add Event</font></td>
</tr>
<tr>
<td><asp:HiddenField ID="hidNewEventID" runat="server" Value="" />
<asp:Label ID="lblNewEventDate" runat="server">Date:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventDate" runat="server" /></td>
</tr>
<tr>
<td><asp:Label ID="lblNewEventTitle" runat="server">Title:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventTitle" Width="200" MaxLength="60" runat="server" /></td>
</tr>
<tr>
<td><asp:Label ID="lblNewEventDesc" runat="server">Description:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventDesc" Width="200" MaxLength="60" runat="server" /></td>
</tr>
<tr>
<td colspan="2" align="right"><br /><asp:Button ID="btnAddEvent" runat="server" text="Add Event" /></td>
</tr>
</table>
</asp:panel>
Hmm Im not a VB guy but have you declared btnAddEvent like:
Protected WithEvents btnAddEvent As System.Web.UI.WebControls.Button ?





I hope it's as easy as you say Tony but when I run in debug mode it won't even compile. The code for the button click event follows.

Protected Sub btnAddEvent_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddEvent.Click
handleAddEventButton()
End Sub

I get the following error:

error BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Thanks for your help. I do appreciate it.
 
K

Ken Sturgeon

I finally got past the issue Tony.


I modified the line in the aspx page where the button is created by adding the OnClick event there.

<asp:Button ID="btnAddEvent" runat="server" text="Add Event" OnClick="handleAddEventButton" />

Created a sub to handle the event in the code behind file.

Public Sub handleAddEventButton()
...
End Sub

I initially got an error saying that the signature of the handler wasn't correct.

Error 1 Method 'Public Sub handleAddEventButton()' does not have the same signature as delegate 'Delegate Sub EventHandler(sender As Object, e As System.EventArgs)'. C:\Inetpub\wwwroot\GW300\Website\CalendarEvents.aspx 53

I modified the sub as follows and all works well.

Public Sub handleAddEventButton(ByVal sender As Object, ByVal e As System.EventArgs)
...
End Sub

Thanks again for your help Tony. I really appreciate your time and attention to my issue.

Do a Find and see if there is another button hidden in a region er something.
Yes, I found a couple threads that indicated that as the solution to the error message I'm getting. When I added it I got the blue squiggly; when I hover over it it says...

btnAddEvent is already declared as 'Protected Dim WithEvents btnAddEvent As System.Web.UI.WebControls.Button' in this class

I don't see it declared anywhere else in the class. The only place it's referenced is in the aspx page where I created it.

<asp:panel ID="pnlAddEvent" runat="server" Width="100%" Direction="LeftToRight" Visible="False">
<hr />
<table>
<tr>
<td colspan="2" class="TableHeader"><font class="TableHeaderFont">Add Event</font></td>
</tr>
<tr>
<td><asp:HiddenField ID="hidNewEventID" runat="server" Value="" />
<asp:Label ID="lblNewEventDate" runat="server">Date:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventDate" runat="server" /></td>
</tr>
<tr>
<td><asp:Label ID="lblNewEventTitle" runat="server">Title:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventTitle" Width="200" MaxLength="60" runat="server" /></td>
</tr>
<tr>
<td><asp:Label ID="lblNewEventDesc" runat="server">Description:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventDesc" Width="200" MaxLength="60" runat="server" /></td>
</tr>
<tr>
<td colspan="2" align="right"><br /><asp:Button ID="btnAddEvent" runat="server" text="Add Event" /></td>
</tr>
</table>
</asp:panel>
Hmm Im not a VB guy but have you declared btnAddEvent like:
Protected WithEvents btnAddEvent As System.Web.UI.WebControls.Button ?





I hope it's as easy as you say Tony but when I run in debug mode it won't even compile. The code for the button click event follows.

Protected Sub btnAddEvent_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddEvent.Click
handleAddEventButton()
End Sub

I get the following error:

error BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Thanks for your help. I do appreciate it.
 
A

Anthony Merante

hehe Cool! Yea i guess i should have asked if you had the button wired up!

Glad to have been of some "help"
I finally got past the issue Tony.


I modified the line in the aspx page where the button is created by adding the OnClick event there.

<asp:Button ID="btnAddEvent" runat="server" text="Add Event" OnClick="handleAddEventButton" />

Created a sub to handle the event in the code behind file.

Public Sub handleAddEventButton()
...
End Sub

I initially got an error saying that the signature of the handler wasn't correct.

Error 1 Method 'Public Sub handleAddEventButton()' does not have the same signature as delegate 'Delegate Sub EventHandler(sender As Object, e As System.EventArgs)'. C:\Inetpub\wwwroot\GW300\Website\CalendarEvents.aspx 53

I modified the sub as follows and all works well.

Public Sub handleAddEventButton(ByVal sender As Object, ByVal e As System.EventArgs)
...
End Sub

Thanks again for your help Tony. I really appreciate your time and attention to my issue.

Do a Find and see if there is another button hidden in a region er something.
Yes, I found a couple threads that indicated that as the solution to the error message I'm getting. When I added it I got the blue squiggly; when I hover over it it says...

btnAddEvent is already declared as 'Protected Dim WithEvents btnAddEvent As System.Web.UI.WebControls.Button' in this class

I don't see it declared anywhere else in the class. The only place it's referenced is in the aspx page where I created it.

<asp:panel ID="pnlAddEvent" runat="server" Width="100%" Direction="LeftToRight" Visible="False">
<hr />
<table>
<tr>
<td colspan="2" class="TableHeader"><font class="TableHeaderFont">Add Event</font></td>
</tr>
<tr>
<td><asp:HiddenField ID="hidNewEventID" runat="server" Value="" />
<asp:Label ID="lblNewEventDate" runat="server">Date:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventDate" runat="server" /></td>
</tr>
<tr>
<td><asp:Label ID="lblNewEventTitle" runat="server">Title:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventTitle" Width="200" MaxLength="60" runat="server" /></td>
</tr>
<tr>
<td><asp:Label ID="lblNewEventDesc" runat="server">Description:</asp:Label></td>
<td style="width: 207px"><asp:TextBox ID="txtNewEventDesc" Width="200" MaxLength="60" runat="server" /></td>
</tr>
<tr>
<td colspan="2" align="right"><br /><asp:Button ID="btnAddEvent" runat="server" text="Add Event" /></td>
</tr>
</table>
</asp:panel>
Hmm Im not a VB guy but have you declared btnAddEvent like:
Protected WithEvents btnAddEvent As System.Web.UI.WebControls.Button ?





I hope it's as easy as you say Tony but when I run in debug mode it won't even compile. The code for the button click event follows.

Protected Sub btnAddEvent_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddEvent.Click
handleAddEventButton()
End Sub

I get the following error:

error BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Thanks for your help. I do appreciate it.
 

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,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top