get CommandArgument from ImageButton onClick, VB

Johanna picture Johanna · Oct 31, 2011 · Viewed 8.8k times · Source

I have a series of ImageButtons...when I click on the image, I want to redirect to another page, using the CommandArgument as a uniqueId...How can i get the commandArgument from the onclick event? Thanks!

Answer

drdwilcox picture drdwilcox · Oct 31, 2011

Don't use the OnClick event. Use the OnCommand event

Protected Sub ImageButton1_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
    Dim arg As String = e.CommandArgument.ToString()

    ' use arg
End Sub