C# linkbutton question object does not contain a definition for CommandArgument

N

needin4mation

I have some VB.NET code that I am trying to convert. I'm not sure what
to do here and was hoping you could help.

Sub PagerButtonClick(sender As Object, e As EventArgs)
'used by external paging UI
Dim arg As String = sender.CommandArgument

is the code from:

http://www.4guysfromrolla.com/webtech/082901-1.2.shtml

I have tried this code in c# (converted as best I could) but I cannot
get the sender.CommandArgument to work.

It's just a button that calls a function on the server side. This
signature:

object sender, System.EventArgs e

does not have an CommandArgument.

I tried a cast like:

(System.Web.UI.WebControls.DataGridCommandEventArgs) sender, but it has
no effect.

I don't know what to do. Thank you for any help. How can I access the
command argument of a button that is not in the datagrid?
 
E

Elton Wang

CommandArgument should come from EventArgs rather than from Object. Try

Dim arg As String = e.CommandArgument

HTH
 
N

needin4mation

I won't work as EventArgs or sender. There is no CommandArgument for
object or System.EventArgs. The VB Code allows it, but not the C# code.
 
Joined
May 28, 2008
Messages
11
Reaction score
0
object does not contain definition for commandArgument

generally this error occured when OnClick=LinkButton1_click instead of LinkButton_Click.i.e. C should be capital in Click.

<asp:LinkButton ID="lbtndetails" CssClass="offfer-price-button" OnClick="lbtndetails_Click" runat="server" CommandName="viewdetails" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "ProductID") %>' >Details</asp:LinkButton>

Second thing is
u can get commandArgument value as follows:

protected void lbtndetails_Click(object sender, EventArgs e)
{
LinkButton mybutton1 = sender as LinkButton;
if (mybutton1 != null)
{
string info = mybutton1.CommandArgument;

Session["pid"] = info;
Response.Redirect("ProductDetail.aspx");
//Response.Write(info);
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top