As you expect, the CommandArgument
is a server-side property of Button
server control and you can't assign it from client-side code because it does not render corresponding HTML attribute. However, you can set up a postback from client-side with __doPostBack()
function as provided below:
<script>
var facility_id = 50;
$('#something').click(function () {
__doPostBack("<%= submitBtn.UniqueID %>", facility_id);
});
</script>
Code behind
protected void submitBtn_Click(object sender, EventArgs e)
{
// assumed 'facility_id' is an int? or Nullable<int> property,
// make sure the event argument is parseable to integer value
var evArg = int.Parse(Request.Form["__EVENTARGUMENT"]);
facility_id = evArg;
}
If you cannot use __doPostBack()
function because it is undefined on the page, then you can handle PreRender
event of that page and provide GetPostBackEventReference()
method:
protected void Page_PreRender(object sender, EventArgs e)
{
ClientScript.GetPostBackEventReference(submitBtn, string.Empty);
}