This VB Code illustrates how to send a value from a button control using the commandArgument and the OnClick attributes and how to use the value in the cod-behind on the click event


'Fron-End code html. The button control should have an Onclick attribute that references a Subroutine 'in your code-behind along with a commandArgument attribute that will carry the value you want

<asp:Button ID="Button2" runat="server" Text='<%# "Stop: " & Eval("Stop") & " " & Eval("ShippingAddress")%>' OnClick = "Button_Click" CommandArgument = '<%# Eval("Stop")%>' CssClass="btn btn-primary" style="width:90%;" />

'Backend / code-behind function that gets the command argument of the button

Protected Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)

'Get the reference of the clicked button.
Dim button As Button = CType(sender, Button)

'Get the command argument
Dim StopNo As String = button.CommandArgument

TripNo = Request("TripNo")
Server.Transfer("mobileTrip.aspx?&TripNo=" & TripNo & "&StopNo=" & StopNo)

End Sub

Tags: commandArgument, OnClick, VB.NET
Last update:
2014-08-19 17:52
Average rating:0 (0 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.

Records in this category