Am Prabhakar Reddy,
Am getting this error,
"
Unable to cast object of type 'System.EventArgs' to type 'System.Web.UI.WebControls.CommandEventArgs'."
how to convert eventargs to commandeventargs
Please help to me
Thank you
how to convert eventargs to commandeventargs
Please help to me
Thank you
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Upamanyu Roy ChoudhuryPosted Feb 23, 2013, 1:02 AM
If you had given the code snippet it would have been much easier to reproduce the error.
Anyway lets say you are using a button and trying to handle a button's click event.
Protected Sub Button1_Click(ByVal Sender As Object, ByVal E As CommandEventArgs)
To handle a button's click event, "CommandEventArgs" should just be "EventArgs".
You can either handle the Command event, or you can cast sender (in the click handler) to Button, and then read the CommandArgument from that.
Button btn1= sender as Button;
if (btn1!= null)
{
// use btn1.CommandArgument here as you see fit.
}
Please keep me informed and mark it as an asnswer if it help you