ASP.NET : Check for click event in page_load

前端 未结 6 1872
孤城傲影
孤城傲影 2020-12-28 09:11

In c#, how can I check to see if a link button has been clicked in the page load method?

I need to know if it was clicked before the click event is fired.

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-28 10:01

    Based on accepted answer and the answer of RealSteel this could be a more complete answer.

    First add to the .aspx a button like this:

    
    

    Then on the Page_Load method:

    if(IsPostBack){
       var eventTarget = Request.Params["__EVENTTARGET"]
       // Then check for the id but keep in mind that the name could be 
       // something like ctl00$ContainerName$btnExport 
       // if the button was clicked or null so take precautions against null
       // ... so it could be something like this
       var buttonClicked = eventTarget.Substring(eventTarget.LastIndexOf("$") + 1).Equals("btnExport")
    
    }
    

提交回复
热议问题