By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,997 Members | 1,470 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,997 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Mar 14 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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

"Ken Sturgeon" <ks*******@genelco.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

Mar 14 '06 #2

P: n/a
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.

"Anthony Merante" <so**********@community.nospam> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
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



"Ken Sturgeon" <ks*******@genelco.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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


Mar 14 '06 #3

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

"Ken Sturgeon" <ks*******@genelco.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
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.

"Anthony Merante" <so**********@community.nospam> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
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



"Ken Sturgeon" <ks*******@genelco.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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


Mar 14 '06 #4

P: n/a
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>
"Anthony Merante" <so**********@community.nospam> wrote in message news:OF**************@TK2MSFTNGP14.phx.gbl...
Hmm Im not a VB guy but have you declared btnAddEvent like:
Protected WithEvents btnAddEvent As System.Web.UI.WebControls.Button ?

"Ken Sturgeon" <ks*******@genelco.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
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.

"Anthony Merante" <so**********@community.nospam> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
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



"Ken Sturgeon" <ks*******@genelco.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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


Mar 14 '06 #5

P: n/a
Do a Find and see if there is another button hidden in a region er something.
"Ken Sturgeon" <ks*******@genelco.com> wrote in message news:Ou**************@tk2msftngp13.phx.gbl...
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>
"Anthony Merante" <so**********@community.nospam> wrote in message news:OF**************@TK2MSFTNGP14.phx.gbl...
Hmm Im not a VB guy but have you declared btnAddEvent like:
Protected WithEvents btnAddEvent As System.Web.UI.WebControls.Button ?

"Ken Sturgeon" <ks*******@genelco.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
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.

"Anthony Merante" <so**********@community.nospam> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
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



"Ken Sturgeon" <ks*******@genelco.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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


Mar 14 '06 #6

P: n/a
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.

"Anthony Merante" <so**********@community.nospam> wrote in message news:eM**************@TK2MSFTNGP11.phx.gbl...
Do a Find and see if there is another button hidden in a region er something.
"Ken Sturgeon" <ks*******@genelco.com> wrote in message news:Ou**************@tk2msftngp13.phx.gbl...
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>
"Anthony Merante" <so**********@community.nospam> wrote in message news:OF**************@TK2MSFTNGP14.phx.gbl...
Hmm Im not a VB guy but have you declared btnAddEvent like:
Protected WithEvents btnAddEvent As System.Web.UI.WebControls.Button ?

"Ken Sturgeon" <ks*******@genelco.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
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.

"Anthony Merante" <so**********@community.nospam> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
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



"Ken Sturgeon" <ks*******@genelco.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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


Mar 14 '06 #7

P: n/a
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.as px 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.

"Anthony Merante" <so**********@community.nospam> wrote in message news:eM**************@TK2MSFTNGP11.phx.gbl...
Do a Find and see if there is another button hidden in a region er something.
"Ken Sturgeon" <ks*******@genelco.com> wrote in message news:Ou**************@tk2msftngp13.phx.gbl...
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>
"Anthony Merante" <so**********@community.nospam> wrote in message news:OF**************@TK2MSFTNGP14.phx.gbl...
Hmm Im not a VB guy but have you declared btnAddEvent like:
Protected WithEvents btnAddEvent As System.Web.UI.WebControls.Button ?

"Ken Sturgeon" <ks*******@genelco.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
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.

"Anthony Merante" <so**********@community.nospam> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
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



"Ken Sturgeon" <ks*******@genelco.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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


Mar 14 '06 #8

P: n/a
hehe Cool! Yea i guess i should have asked if you had the button wired up!

Glad to have been of some "help"
"Ken Sturgeon" <ks*******@genelco.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl...
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.as px 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.

"Anthony Merante" <so**********@community.nospam> wrote in message news:eM**************@TK2MSFTNGP11.phx.gbl...
Do a Find and see if there is another button hidden in a region er something.
"Ken Sturgeon" <ks*******@genelco.com> wrote in message news:Ou**************@tk2msftngp13.phx.gbl...
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>
"Anthony Merante" <so**********@community.nospam> wrote in message news:OF**************@TK2MSFTNGP14.phx.gbl...
Hmm Im not a VB guy but have you declared btnAddEvent like:
Protected WithEvents btnAddEvent As System.Web.UI.WebControls.Button ?

"Ken Sturgeon" <ks*******@genelco.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
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.

"Anthony Merante" <so**********@community.nospam> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
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



"Ken Sturgeon" <ks*******@genelco.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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


Mar 14 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.