Like the other responses have shown, because we don't know what type of object is calling this method, it's hard to diagnose. If you are using CommandEventArgs, it has a CommandArgument property that should be set. If, however, you're calling this yourself and passing
null
as the CommandEventArgs, then you will get an error.
If the object (ie
sender
) has a CommandArgument, then you need to case sender before calling it to the type that it is.
object
is a base class and does not contain CommandArgument, which is what the error is telling you.
For instance, if this was a RichTextBox and we were handling the TextChanged event, we could use
string RTF = (RichTextBox)sender.Rtf;
but we would get the same error you got if we tried
string RTF = sender.Rtf;
What kind of object is calling this method? Is this a Button from the System.Web.UI.WebControls class? If so, try:
string arg = (System.Web.UI.WebControls.Button)sender.CommandArgument.ToString();