How to check if request is ajax or not in codebehind - ASP.NET Webforms

后端 未结 6 1573
余生分开走
余生分开走 2020-12-05 04:26

I tried the Request.IsAjaxRequest but this does not exist in WebForms. I am making a JQuery ajax call. How do I check if this is a ajax request or not in C#?

6条回答
  •  囚心锁ツ
    2020-12-05 05:12

    Decorate your class with [WebMethod(EnableSession = true)]syntax like if you write the following function in code behind and call the same function from ajax call you will be sure.

    [WebMethod(EnableSession = true)]
        public static void   getData(string JSONFirstData,string JSONSecondData, string JSONThirdData, string JSONForthData, ...)
        {
           //code
        }
    

    in Ajax URL be like URL :'/Codebehind.aspx/getData'

提交回复
热议问题