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#?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Using :remote => true with hover event
- How to store image outside of the website's ro
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.in Ajax URL be like
URL :'/Codebehind.aspx/getData'
You could create your own extension method much like the one in the MVC code
E.g.
HTHs,
Charles
Edit: Actually Callback requests are also ajax requests,
Generally, you will need to test for the
X-Requested-With
header, ensuring that its value is 'XMLHttpRequest'. I'm not a C# developer (yet), but a quick google search says that in C# it goes something like this:Try to check if the ScriptManager IsInAsyncPostBack :
Yes,
Request.IsAjaxRequest
looks at the headers and the querystring forX-Requested-With
, but it seems your jquery isn't sending theX-Requested-With
header.You can try and see what headers it is sending by using Fiddler, or alternatively just send it in the querystring by setting the POST url to
/whatever.aspx?x-requested-with=XMLHttpRequest