Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Problems with LinkButtons


Message #1 by "Hugh McLaughlin" <hugh@k...> on Wed, 27 Nov 2002 02:51:56
Hello Everyone and thanks for your help in advance.  I am writing a 
contact management application that can be viewed at:

http://www.hughmclaughlin.com/ContactManager.aspx

I am developing the application using Visual Studio and I am stuck on a 
couple of issues.  The problem I am having is with the link button at the 
top (A,B, etc.).  When they are clicked, the OnCommand event should fire 
and pass a CommandArgument (the letter) to a subroutine that then queries 
the database and then binds the data.  However it is not working properly 
and I am not sure why.  The subroutine that handles the code behind file 
and the linkbutton code looks like:

    Sub LinkButton_Click(ByVal sender As System.Object, ByVal e As 
CommandEventArgs)
        Dim strSearchLetter As String = e.CommandArgument
        Dim SQL As String = "select * from tblMembers WHERE LastName 
LIKE '" & strSearchLetter & "%'"
        SQLText.Text = SQL
        BindData()
    End Sub

The link Button looks like this:

<asp:linkbutton id="LinkButtonA" runat="server" 
OnCommand="LinkButton_Click" CommandArgument="A">A</asp:linkbutton>

I want to utilize the same subroutine for each letter, thus the OnCommand 
and CommandArgument methods.  However, the click event does not appear to 
pass the proper argument.  Additionally, in Visual Studio, I cannot seem 
to find where to set the OnCommand property of the link button, except 
manually in the code-behind file.  Also, Visual Studion seems to want to 
handle each LinkButton with its own subroutine.  Any help on these issues 
would be greatly appreciated.  Thanks.
Message #2 by "yohohuangtao0425" <yohohuangtao0425@s...> on Wed, 27 Nov 2002 11:38:46 -0800
you sub has something wrong!
please chang you LinkButton_Click with " public Sub LinkButton_Click(ByVal sender As System.Object, ByVal e As CommandEventArgs)".
and try again.



Hello Everyone and thanks for your help in advance.  I am writing a 
contact management application that can be viewed at:

http://www.hughmclaughlin.com/ContactManager.aspx

I am developing the application using Visual Studio and I am stuck on a 
couple of issues.  The problem I am having is with the link button at the 
top (A,B, etc.).  When they are clicked, the OnCommand event should fire 
and pass a CommandArgument (the letter) to a subroutine that then queries 
the database and then binds the data.  However it is not working properly 
and I am not sure why.  The subroutine that handles the code behind file 
and the linkbutton code looks like:

    Sub LinkButton_Click(ByVal sender As System.Object, ByVal e As 
CommandEventArgs)
        Dim strSearchLetter As String = e.CommandArgument
        Dim SQL As String = "select * from tblMembers WHERE LastName 
LIKE '" & strSearchLetter & "%'"
        SQLText.Text = SQL
        BindData()
    End Sub

The link Button looks like this:

<< asp:linkbutton id="LinkButtonA" runat="server" 
OnCommand="LinkButton_Click" CommandArgument="A"> A< /asp:linkbutton> 

I want to utilize the same subroutine for each letter, thus the OnCommand 
and CommandArgument methods.  However, the click event does not appear to 
pass the proper argument.  Additionally, in Visual Studio, I cannot seem 
to find where to set the OnCommand property of the link button, except 
manually in the code-behind file.  Also, Visual Studion seems to want to 
handle each LinkButton with its own subroutine.  Any help on these issues 
would be greatly appreciated.  Thanks.

Message #3 by "Hugh McLaughlin" <hugh@k...> on Wed, 27 Nov 2002 13:27:25
I made this change and it had not effect.

> you sub has something wrong!
please chang you LinkButton_Click with " public Sub LinkButton_Click
(ByVal sender As System.Object, ByVal e As CommandEventArgs)".
and try again.



Hello Everyone and thanks for your help in advance.  I am writing a 
contact management application that can be viewed at:

http://www.hughmclaughlin.com/ContactManager.aspx

I am developing the application using Visual Studio and I am stuck on a 
couple of issues.  The problem I am having is with the link button at the 
top (A,B, etc.).  When they are clicked, the OnCommand event should fire 
and pass a CommandArgument (the letter) to a subroutine that then queries 
the database and then binds the data.  However it is not working properly 
and I am not sure why.  The subroutine that handles the code behind file 
and the linkbutton code looks like:

    Sub LinkButton_Click(ByVal sender As System.Object, ByVal e As 
CommandEventArgs)
        Dim strSearchLetter As String = e.CommandArgument
        Dim SQL As String = "select * from tblMembers WHERE LastName 
LIKE '" & strSearchLetter & "%'"
        SQLText.Text = SQL
        BindData()
    End Sub

The link Button looks like this:

<< asp:linkbutton id="LinkButtonA" runat="server" 
OnCommand="LinkButton_Click" CommandArgument="A"> A< /asp:linkbutton> 

I want to utilize the same subroutine for each letter, thus the OnCommand 
and CommandArgument methods.  However, the click event does not appear to 
pass the proper argument.  Additionally, in Visual Studio, I cannot seem 
to find where to set the OnCommand property of the link button, except 
manually in the code-behind file.  Also, Visual Studion seems to want to 
handle each LinkButton with its own subroutine.  Any help on these issues 
would be greatly appreciated.  Thanks.

Message #4 by "Dave Rezoski" <daverezoski@h...> on Wed, 27 Nov 2002 17:09:22 +0000
are you stepping through your code with the debugger?  Do you know if the 
event gets fired and trapped?  if the sub is getting called, is the command 
argument being passed?

perhaps you're binding the page again after the button click and therefore 
don't actually see the results of the sub being fired onclick?






----Original Message Follows----
From: "Hugh McLaughlin" <hugh@k...>
Reply-To: "ASP.NET" <aspx@p...>
To: "ASP.NET" <aspx@p...>
Subject: [aspx] Re: Problems with LinkButtons
Date: Wed, 27 Nov 2002 13:27:25

I made this change and it had not effect.

 > you sub has something wrong!
please chang you LinkButton_Click with " public Sub LinkButton_Click
(ByVal sender As System.Object, ByVal e As CommandEventArgs)".
and try again.



Hello Everyone and thanks for your help in advance.  I am writing a
contact management application that can be viewed at:

http://www.hughmclaughlin.com/ContactManager.aspx

I am developing the application using Visual Studio and I am stuck on a
couple of issues.  The problem I am having is with the link button at the
top (A,B, etc.).  When they are clicked, the OnCommand event should fire
and pass a CommandArgument (the letter) to a subroutine that then queries
the database and then binds the data.  However it is not working properly
and I am not sure why.  The subroutine that handles the code behind file
and the linkbutton code looks like:

     Sub LinkButton_Click(ByVal sender As System.Object, ByVal e As
CommandEventArgs)
         Dim strSearchLetter As String = e.CommandArgument
         Dim SQL As String = "select * from tblMembers WHERE LastName
LIKE '" & strSearchLetter & "%'"
         SQLText.Text = SQL
         BindData()
     End Sub

The link Button looks like this:

<< asp:linkbutton id="LinkButtonA" runat="server"
OnCommand="LinkButton_Click" CommandArgument="A"> A< /asp:linkbutton>

I want to utilize the same subroutine for each letter, thus the OnCommand
and CommandArgument methods.  However, the click event does not appear to
pass the proper argument.  Additionally, in Visual Studio, I cannot seem
to find where to set the OnCommand property of the link button, except
manually in the code-behind file.  Also, Visual Studion seems to want to
handle each LinkButton with its own subroutine.  Any help on these issues
would be greatly appreciated.  Thanks.



_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. 
http://join.msn.com/?page=features/virus

Message #5 by "Hugh McLaughlin" <hugh@k...> on Wed, 27 Nov 2002 20:03:15
The event sub is firing.  If you go to the example I have posted, you will 
notice that the SQL statement is posted for "A" when the A link is 
clicked.  The search box, located in anoter sub, is also firing okay.  
However, it appears that when the "B" link is clicked, the SQL stays 
at "A".  My suspicion is that the command argument is not functioning 
properly.

> are you stepping through your code with the debugger?  Do you know if 
the 
event gets fired and trapped?  if the sub is getting called, is the 
command 
argument being passed?

perhaps you're binding the page again after the button click and therefore 
don't actually see the results of the sub being fired onclick?






----Original Message Follows----
From: "Hugh McLaughlin" <hugh@k...>
Reply-To: "ASP.NET" <aspx@p...>
To: "ASP.NET" <aspx@p...>
Subject: [aspx] Re: Problems with LinkButtons
Date: Wed, 27 Nov 2002 13:27:25

I made this change and it had not effect.

 > you sub has something wrong!
please chang you LinkButton_Click with " public Sub LinkButton_Click
(ByVal sender As System.Object, ByVal e As CommandEventArgs)".
and try again.



Hello Everyone and thanks for your help in advance.  I am writing a
contact management application that can be viewed at:

http://www.hughmclaughlin.com/ContactManager.aspx

I am developing the application using Visual Studio and I am stuck on a
couple of issues.  The problem I am having is with the link button at the
top (A,B, etc.).  When they are clicked, the OnCommand event should fire
and pass a CommandArgument (the letter) to a subroutine that then queries
the database and then binds the data.  However it is not working properly
and I am not sure why.  The subroutine that handles the code behind file
and the linkbutton code looks like:

     Sub LinkButton_Click(ByVal sender As System.Object, ByVal e As
CommandEventArgs)
         Dim strSearchLetter As String = e.CommandArgument
         Dim SQL As String = "select * from tblMembers WHERE LastName
LIKE '" & strSearchLetter & "%'"
         SQLText.Text = SQL
         BindData()
     End Sub

The link Button looks like this:

<< asp:linkbutton id="LinkButtonA" runat="server"
OnCommand="LinkButton_Click" CommandArgument="A"> A< /asp:linkbutton>

I want to utilize the same subroutine for each letter, thus the OnCommand
and CommandArgument methods.  However, the click event does not appear to
pass the proper argument.  Additionally, in Visual Studio, I cannot seem
to find where to set the OnCommand property of the link button, except
manually in the code-behind file.  Also, Visual Studion seems to want to
handle each LinkButton with its own subroutine.  Any help on these issues
would be greatly appreciated.  Thanks.



_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. 
http://join.msn.com/?page=features/virus

Message #6 by "Dave Rezoski" <daverezoski@h...> on Wed, 27 Nov 2002 22:19:44 +0000
try renaming you sub ...

Private Sub ChangeLetter(ByVal sender As System.Object, ByVal e As
CommandEventArgs)
          Dim strSearchLetter As String = e.CommandArgument
          Dim SQL As String = "select * from tblMembers WHERE LastName
LIKE '" & strSearchLetter & "%'"
          SQLText.Text = SQL
          BindData()
End Sub

and in you aspx code, reference the commandname, as well as the arguement, 
like this:

<asp:linkbutton runat="server" CommandName="ChangeLetter" 
CommandArgument="A">A</asp:linkbutton>

lemme know ...





----Original Message Follows----
From: "Hugh McLaughlin" <hugh@k...>
Reply-To: "ASP.NET" <aspx@p...>
To: "ASP.NET" <aspx@p...>
Subject: [aspx] Re: Problems with LinkButtons
Date: Wed, 27 Nov 2002 20:03:15

The event sub is firing.  If you go to the example I have posted, you will
notice that the SQL statement is posted for "A" when the A link is
clicked.  The search box, located in anoter sub, is also firing okay.
However, it appears that when the "B" link is clicked, the SQL stays
at "A".  My suspicion is that the command argument is not functioning
properly.

 > are you stepping through your code with the debugger?  Do you know if
the
event gets fired and trapped?  if the sub is getting called, is the
command
argument being passed?

perhaps you're binding the page again after the button click and therefore
don't actually see the results of the sub being fired onclick?






----Original Message Follows----
From: "Hugh McLaughlin" <hugh@k...>
Reply-To: "ASP.NET" <aspx@p...>
To: "ASP.NET" <aspx@p...>
Subject: [aspx] Re: Problems with LinkButtons
Date: Wed, 27 Nov 2002 13:27:25

I made this change and it had not effect.

  > you sub has something wrong!
please chang you LinkButton_Click with " public Sub LinkButton_Click
(ByVal sender As System.Object, ByVal e As CommandEventArgs)".
and try again.



Hello Everyone and thanks for your help in advance.  I am writing a
contact management application that can be viewed at:

http://www.hughmclaughlin.com/ContactManager.aspx

I am developing the application using Visual Studio and I am stuck on a
couple of issues.  The problem I am having is with the link button at the
top (A,B, etc.).  When they are clicked, the OnCommand event should fire
and pass a CommandArgument (the letter) to a subroutine that then queries
the database and then binds the data.  However it is not working properly
and I am not sure why.  The subroutine that handles the code behind file
and the linkbutton code looks like:

      Sub LinkButton_Click(ByVal sender As System.Object, ByVal e As
CommandEventArgs)
          Dim strSearchLetter As String = e.CommandArgument
          Dim SQL As String = "select * from tblMembers WHERE LastName
LIKE '" & strSearchLetter & "%'"
          SQLText.Text = SQL
          BindData()
      End Sub

The link Button looks like this:

<< asp:linkbutton id="LinkButtonA" runat="server"
OnCommand="LinkButton_Click" CommandArgument="A"> A< /asp:linkbutton>

I want to utilize the same subroutine for each letter, thus the OnCommand
and CommandArgument methods.  However, the click event does not appear to
pass the proper argument.  Additionally, in Visual Studio, I cannot seem
to find where to set the OnCommand property of the link button, except
manually in the code-behind file.  Also, Visual Studion seems to want to
handle each LinkButton with its own subroutine.  Any help on these issues
would be greatly appreciated.  Thanks.



_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus



_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* 
http://join.msn.com/?page=features/junkmail

Message #7 by "Hugh McLaughlin" <hugh@k...> on Thu, 28 Nov 2002 00:54:11
Still no luck.  Additionally, when I use only the CommandName attribute, 
the event fails to fire at all.  It looks like it only fires the A 
paramter.  Can't figure out why.

> try renaming you sub ...

Private Sub ChangeLetter(ByVal sender As System.Object, ByVal e As
CommandEventArgs)
          Dim strSearchLetter As String = e.CommandArgument
          Dim SQL As String = "select * from tblMembers WHERE LastName
LIKE '" & strSearchLetter & "%'"
          SQLText.Text = SQL
          BindData()
End Sub

and in you aspx code, reference the commandname, as well as the 
arguement, 
like this:

<asp:linkbutton runat="server" CommandName="ChangeLetter" 
CommandArgument="A">A</asp:linkbutton>

lemme know ...





----Original Message Follows----
From: "Hugh McLaughlin" <hugh@k...>
Reply-To: "ASP.NET" <aspx@p...>
To: "ASP.NET" <aspx@p...>
Subject: [aspx] Re: Problems with LinkButtons
Date: Wed, 27 Nov 2002 20:03:15

The event sub is firing.  If you go to the example I have posted, you will
notice that the SQL statement is posted for "A" when the A link is
clicked.  The search box, located in anoter sub, is also firing okay.
However, it appears that when the "B" link is clicked, the SQL stays
at "A".  My suspicion is that the command argument is not functioning
properly.

 > are you stepping through your code with the debugger?  Do you know if
the
event gets fired and trapped?  if the sub is getting called, is the
command
argument being passed?

perhaps you're binding the page again after the button click and therefore
don't actually see the results of the sub being fired onclick?






----Original Message Follows----
From: "Hugh McLaughlin" <hugh@k...>
Reply-To: "ASP.NET" <aspx@p...>
To: "ASP.NET" <aspx@p...>
Subject: [aspx] Re: Problems with LinkButtons
Date: Wed, 27 Nov 2002 13:27:25

I made this change and it had not effect.

  > you sub has something wrong!
please chang you LinkButton_Click with " public Sub LinkButton_Click
(ByVal sender As System.Object, ByVal e As CommandEventArgs)".
and try again.



Hello Everyone and thanks for your help in advance.  I am writing a
contact management application that can be viewed at:

http://www.hughmclaughlin.com/ContactManager.aspx

I am developing the application using Visual Studio and I am stuck on a
couple of issues.  The problem I am having is with the link button at the
top (A,B, etc.).  When they are clicked, the OnCommand event should fire
and pass a CommandArgument (the letter) to a subroutine that then queries
the database and then binds the data.  However it is not working properly
and I am not sure why.  The subroutine that handles the code behind file
and the linkbutton code looks like:

      Sub LinkButton_Click(ByVal sender As System.Object, ByVal e As
CommandEventArgs)
          Dim strSearchLetter As String = e.CommandArgument
          Dim SQL As String = "select * from tblMembers WHERE LastName
LIKE '" & strSearchLetter & "%'"
          SQLText.Text = SQL
          BindData()
      End Sub

The link Button looks like this:

<< asp:linkbutton id="LinkButtonA" runat="server"
OnCommand="LinkButton_Click" CommandArgument="A"> A< /asp:linkbutton>

I want to utilize the same subroutine for each letter, thus the OnCommand
and CommandArgument methods.  However, the click event does not appear to
pass the proper argument.  Additionally, in Visual Studio, I cannot seem
to find where to set the OnCommand property of the link button, except
manually in the code-behind file.  Also, Visual Studion seems to want to
handle each LinkButton with its own subroutine.  Any help on these issues
would be greatly appreciated.  Thanks.



_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus



_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* 
http://join.msn.com/?page=features/junkmail

Message #8 by "Ken Schaefer" <ken@a...> on Thu, 28 Nov 2002 12:59:35 +1100
You are missing:

onCommand="...routine to handle Command event..."

You have instead:

commandName="...xxx..."

which is passed to the routine that handles the Command event.

Cheers
Ken

PS the following works fine:

<script runat="server">

    Sub ChangeLetter(ByVal sender as Object, ByVal e as CommandEventArgs)

        Dim strCriteria as String = e.CommandArgument.ToString()
        Dim strSQL as String = "SELECT Field1 FROM myTable WHERE UserName
LIKE '" & strCriteria & "%'"

        myLabel.Text = strSQL

    End Sub

</script>

<html>
   <body>

    <form runat="server" id="myForm">
        <asp:linkbutton id="LinkButtonA" runat="server"
onCommand="ChangeLetter" commandArgument="A">A</asp:linkbutton>
        <asp:linkbutton id="LinkButtonB" runat="server"
onCommand="ChangeLetter" commandArgument="B">B</asp:linkbutton>
    </form>
    <asp:label id="myLabel" runat="server"/>
   </body>
</html>




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Hugh McLaughlin" <hugh@k...>
Subject: [aspx] Re: Problems with LinkButtons


: Still no luck.  Additionally, when I use only the CommandName attribute,
: the event fails to fire at all.  It looks like it only fires the A
: paramter.  Can't figure out why.
:
: > try renaming you sub ...
:
: Private Sub ChangeLetter(ByVal sender As System.Object, ByVal e As
: CommandEventArgs)
:           Dim strSearchLetter As String = e.CommandArgument
:           Dim SQL As String = "select * from tblMembers WHERE LastName
: LIKE '" & strSearchLetter & "%'"
:           SQLText.Text = SQL
:           BindData()
: End Sub
:
: and in you aspx code, reference the commandname, as well as the
: arguement,
: like this:
:
: <asp:linkbutton runat="server" CommandName="ChangeLetter"
: CommandArgument="A">A</asp:linkbutton>
:
: lemme know ...

Message #9 by "yohohuangtao0425" <yohohuangtao0425@s...> on Fri, 29 Nov 2002 10:8:23 -0800
ht
    Changed you SUB to this!

  Private Sub LinkButtonA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButtonA.Click

    End Sub

ht
>Hello Everyone and thanks for your help in advance.  I am writing a 
>contact management application that can be viewed at:
>
>http://www.hughmclaughlin.com/ContactManager.aspx
>
>I am developing the application using Visual Studio and I am stuck on a 
>couple of issues.  The problem I am having is with the link button at the 
>top (A,B, etc.).  When they are clicked, the OnCommand event should fire 
>and pass a CommandArgument (the letter) to a subroutine that then queries 
>the database and then binds the data.  However it is not working properly 
>and I am not sure why.  The subroutine that handles the code behind file 
>and the linkbutton code looks like:
>
>    Sub LinkButton_Click(ByVal sender As System.Object, ByVal e As 
>CommandEventArgs)
>        Dim strSearchLetter As String = e.CommandArgument
>        Dim SQL As String = "select * from tblMembers WHERE LastName 
>LIKE '" & strSearchLetter & "'"
>        SQLText.Text = SQL
>        BindData()
>    End Sub
>
>The link Button looks like this:
>
><asp:linkbutton id="LinkButtonA" runat="server" 
>OnCommand="LinkButton_Click" CommandArgument="A">A</asp:linkbutton>
>
>I want to utilize the same subroutine for each letter, thus the OnCommand 
>and CommandArgument methods.  However, the click event does not appear to 
>pass the proper argument.  Additionally, in Visual Studio, I cannot seem 
>to find where to set the OnCommand property of the link button, except 
>manually in the code-behind file.  Also, Visual Studion seems to want to 
>handle each LinkButton with its own subroutine.  Any help on these issues 
>would be greatly appreciated.  Thanks.




  Return to Index