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. Advertisements

  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. Advertisements

  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
    Likes Received:
    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);
    }

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

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. Ashish Kanoongo
    Replies:
    1
    Views:
    772
    Vjekoslav Babic
    Feb 3, 2004
  2. Columbia Pike
    Replies:
    5
    Views:
    30,419
    Columbia Pike
    Aug 9, 2004
  3. Justin Dutoit
    Replies:
    3
    Views:
    3,773
    =?Utf-8?B?dG9tIHdpc25vd3NraQ==?=
    Oct 7, 2004
  4. Luis Esteban Valencia
    Replies:
    1
    Views:
    4,636
    =?Utf-8?B?Vmtv?=
    Jan 6, 2005
  5. Patrick Olurotimi Ige

    commandargument in linkbutton Question

    Patrick Olurotimi Ige, Jun 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    2,406
    Patrick Olurotimi Ige
    Jun 20, 2005
  6. jobs
    Replies:
    1
    Views:
    758
    Teemu Keiski
    Feb 14, 2007
  7. beacon123
    Replies:
    0
    Views:
    414
    beacon123
    Sep 17, 2009
  8. Jason Carlton
    Replies:
    11
    Views:
    472
    Dr J R Stockton
    Dec 8, 2009
Loading...