CommandArgument is a fully server-side property and does not display the html attribute. Thus, you cannot change any button attribute and click on it. The good news is that you can trigger the postback using the __doPostBack function on the client side and pass your custom value as the second parameter:
<script type="text/javascript"> $("a").click(function () { var val = $(this).attr('id').toString(); __doPostBack("<%= btn1.UniqueID %>", val); }); </script>
And you can get the passed argument in the server click handler from the Request.Form collection:
protected void button_click(object sender, EventArgs e) { var argument = Request.Form["__EVENTARGUMENT"]; }
If the script above will not work, perhaps the __doPostBack function is not defined on the page. In this case, add this code to the Page_PreRender method: ClientScript.GetPostBackEventReference(btn1, string.Empty); , this will cause the page to define the __doPostBack method on the page.
source share