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

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

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

  2. needin4mation

    Elton Wang Guest

    CommandArgument should come from EventArgs rather than from Object. Try

    Dim arg As String = e.CommandArgument

    HTH
     
    Elton Wang, Oct 13, 2005
    #2
    1. Advertisements

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

    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

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 (here). After that, you can post your question and our members will help you out.