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

Discussion in 'ASP .Net' started by needin4mation@gmail.com, Oct 12, 2005.

  1. Guest

    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?
    , Oct 12, 2005
    #1
    1. Advertising

  2. Elton Wang Guest

    CommandArgument should come from EventArgs rather than from Object. Try

    Dim arg As String = e.CommandArgument

    HTH



    <> wrote in message
    news:...
    >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?
    >
    Elton Wang, Oct 13, 2005
    #2
    1. Advertising

  3. Guest

    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.
    , Oct 13, 2005
    #3
  4. swati254

    Joined:
    May 28, 2008
    Messages:
    11
    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);
    }

    }
    swati254, Dec 23, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QmVuamFtaW4gSm9sZGVyc21h?=

    LinkButton CommandArgument bound property loses value on postback

    =?Utf-8?B?QmVuamFtaW4gSm9sZGVyc21h?=, Aug 21, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    4,097
    =?Utf-8?B?QmVuamFtaW4gSm9sZGVyc21h?=
    Aug 21, 2004
  2. Patrick Olurotimi Ige

    commandargument in linkbutton Question

    Patrick Olurotimi Ige, Jun 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    2,247
    Patrick Olurotimi Ige
    Jun 20, 2005
  3. jobs
    Replies:
    1
    Views:
    652
    Teemu Keiski
    Feb 14, 2007
  4. beacon123
    Replies:
    0
    Views:
    301
    beacon123
    Sep 17, 2009
  5. Jason Carlton
    Replies:
    11
    Views:
    235
    Dr J R Stockton
    Dec 8, 2009
Loading...

Share This Page