Search code examples
asp.netevent-handlingasp.net-3.5sendercommandargument

Property 'CommandArgument' is WriteOnly


I have the following line in my code, inside the click event handler of an ImageButton:

Protected Sub FinaliseBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FinaliseBtn.Click, SubmitPaymentViaChequeBtn.Click
   Dim str as String = sender.commandargument.ToString.ToLower
End Sub

Both Controls are ImageButton's. However, I'm getting the following error:

Property 'CommandArgument' is WriteOnly.

Can anyone see why I'm getting this error as usually I can read from a CommandArgument inside an event handler. In fact, surely thats their main use!

Thanks.


Solution

  • You've wired up an event for EventArgs, but trying to retrieve CommandArgs.

    This should be your method:

    Sub ImageButton_Command(sender As Object, e As CommandEventArgs) 
             If (e.CommandName = "Sort") And (e.CommandArgument = "Ascending") Then
                Label1.Text = "You clicked the Sort Ascending Button"
             Else
                Label1.Text = "You clicked the Sort Descending Button"
             End If
          End Sub