Call ASP.NET function from JavaScript?

后端 未结 20 2207
暗喜
暗喜 2020-11-22 07:21

I\'m writing a web page in ASP.NET. I have some JavaScript code, and I have a submit button with a click event.

Is it possible to call a method I created in ASP with

20条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 08:17

    I try this and so I could run an Asp.Net method while using jQuery.

    1. Do a page redirect in your jQuery code

      window.location = "Page.aspx?key=1";
      
    2. Then use a Query String in Page Load

      protected void Page_Load(object sender, EventArgs e)
      {
          if (Request.QueryString["key"] != null)
          {
              string key= Request.QueryString["key"];
              if (key=="1")
              {
                  // Some code
              }
          }
      }
      

    So no need to run an extra code

提交回复
热议问题