Calling C# function through Javascript (without Json)

前端 未结 3 1850
走了就别回头了
走了就别回头了 2021-01-14 06:19

I have a function named \"callfunction()\" in JavaScript(Mypage.aspx) .This function should call another function \"func()\" in C# (Mypage.aspx.cs )

Something like

3条回答
  •  有刺的猬
    2021-01-14 06:44

    If it's a webforms project (not MVC) and you don't want to use AJAX, you can use __doPostBack.

    
    

    C#:

    public void Page_Load(object sender, EventArgs e)
    {
      string parameter = Request["__EVENTARGUMENT"]; // parameter
      var senderObject = Request["__EVENTTARGET"]; // func
      if(senderObject == "func")
      {
         //call your function here, or write the implementation
      }
    }
    

提交回复
热议问题