views:

1121

answers:

3

Is it possible to get a button's command argument in javascript. I don't want to manipulate it, i just want to read it.

If possible - how?

+1  A: 

You can put command argument into some hidden field, then retrieve the value of the hidden field in javascript after page loads such as $(document).ready() in JQuery.

J.W.
This is the only way. The command argument exists only on the server side as far as I know.
womp
A: 

The short answer is NO if you are ONLY using javascript. But you could retrieve it with an ajax call to the server or using a hidden field like J.W. suggested. This property is not even accessible from themes. For more info read the documentation in msdn

Raúl Roa
+7  A: 

Make your own attribute and get it with standard JavaScript:

Markup:

<asp:LinkButton ID="LinkButton1" cmdname="test" CommandName="test" CommandArgument="1" 
    runat="server" onclick="LinkButton1_Click">LinkButton</asp:LinkButton>

Script:

//however you choose to get the element, jQuery...etc
document.getElementById('<%=LinkButton1.ClientID %>').cmdname
rick schott
you are a beast!! I didn't know you can make up your own property. I've been at this for hours now!!! thanks rick!! if i could give you more points i would.
Eric
Glad it worked for you, wish you could too! :)
rick schott