hhh3112
hhh3112

Reputation: 2187

i don't know how to work with command argument in asp.net

i'm tryng to pass a parameter with command argument with a link button but the result i get is always "".

this is in my aspx page:

<%
LinkButton1.CommandArgument = "abcdef";                                 
%>
<asp:LinkButton ID="LinkButton1" runat="server" OnCommand= "LinkButton1_Click">

and in my aspx.cs i have:

protected void LinkButton1_Click(object sender,CommandEventArgs ee)
{
    String id = ee.CommandName.ToString();
}

the id is always "" after i press the linkbutton.

would appreciate if someone could help me. thanks

Upvotes: 0

Views: 1136

Answers (3)

Jonathan Wood
Jonathan Wood

Reputation: 67195

I'm not at my dev machine but it would be more like this:

<asp:LinkButton ID="LinkButton1" runat="server"
    CommandArgument="abcdef" OnCommand="LinkButton1_Click" >

And then check CommandArgument in your code.

Upvotes: 0

Vadim
Vadim

Reputation: 17957

You're setting the CommandArgument in your aspx, but checking the CommandName in your event handler.

Upvotes: 0

John Saunders
John Saunders

Reputation: 161773

Try something like this:

<asp:LinkButton id="LinkButton1" 
           Text="Order Item 10001"
           CommandName="Order" 
           CommandArgument="10001" 
           OnCommand="LinkButton_Command" 
           runat="server"/>

From the example at LinkButton.CommandArgument Property.

Upvotes: 1

Related Questions