Jquery - Pass asp button command argument with jquery

前端 未结 5 1680
野的像风
野的像风 2020-12-18 07:11

I have asp button:


         


        
5条回答
  •  抹茶落季
    2020-12-18 08:02

    CommandArgument is completely a server-side property and doesn't render any html attribute. So you can't change any button's attribute and fire click on it. The good news is that you can fire postback with client-side __doPostBack function and pass your custom value as second parameter:

    
    

    And you can get passed argument in server click handler from the Request.Form collection:

    protected void button_click(object sender, EventArgs e)
    {
        var argument = Request.Form["__EVENTARGUMENT"];
    }
    

    If script above won't work then maybe __doPostBack function not defined on page. In this case add this code to Page_PreRender method: ClientScript.GetPostBackEventReference(btn1, string.Empty); this will force page to define __doPostBack method on page.

提交回复
热议问题