views:

19

answers:

1

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.

A: 

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
RPM1984
I've tried the following: Dim _btn As ImageButton = TryCast(sender, ImageButton) Select Case _btn.CommandArgument However, I get the error: Object reference not set to an instance of an object. Cheers
Curt
See my edit. :)
RPM1984
Sorry, it looks like one of my buttons is a UserControl containing an ImageButton, not just 2 ImageButtons! However, this answer helped me find that solution, thanks :D
Curt
Yes, that would have been helpful information previously. :) Glad you got it sorted.
RPM1984
Ha yeah sorry about that! But thanks for your help :)
Curt