• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

Firing an event on a button control inside a table control vb.net

i need to wriite a sub  to be fired when the buttin clicked, But it seems that when the control is inside a table control cannot be accessed directlly
Protected Sub SendPax_Click  
some code
end sub
<asp:Table ID="PaxTable" runat="server" Width="344px" Height="32px">
  <asp:TableHeaderRow><asp:TableHeaderCell ColumnSpan="5">Please enter passenger names</asp:TableHeaderCell>
      <asp:TableCell HorizontalAlign="right">
          <asp:Button ID="SendPax" runat="server" Text="Send" />  &nbsp;
VB code
Dim Row As Integer
        Dim Col As Integer
        For Row = 1 To PAX
            Dim newRow As New TableRow
            newRow = New TableRow
            For Col = 0 To 3
                Dim newCell = New TableCell
                If Col = 0 Then
                    newCell.Text = Row
                ElseIf Col = 1 Then
                    Dim txtbox As New TextBox
                    txtbox.ID = "First" & Row
                ElseIf Col = 2 Then
                    Dim txtbox As New TextBox
                    txtbox.ID = "Last" & Row
                End If
            Next Col
            newRow = Nothing
        Next Row

Open in new window

  • 2
  • 2
1 Solution

Instead of putting the code inside the button event, put it in the a new sub. In this way you do not need to call the event, but instead you call the sub routine.

For example:

Protected Sub SendPax_Click
End Sub

Protected Sub ExecuteCode()
   'Your code when the Button was clicked.
End Sub
NabilbahrAuthor Commented:
my concern is to be able to run some code when the button is clicked
How to catch an the click event and run some code when clicked
the control is inside a table control
NabilbahrAuthor Commented:
thank you , you were right
Set the modifier property of the button to Public.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now