Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HI Sir,


I am doing a asp.net Project and on a master page am using a jquery ajax code to call the function in code behind. Below here the ajax code that i am using in the master page.


JavaScript
$.ajax({
                                   type: "POST",
                                   url: "../../main.master/abc",
                                   data: {},
                                   contentType: "application/json; charset=utf-8",
                                   dataType: "json"


                               });


And here is the below code that i am using in the master page;

C#
[WebMethod]
public void abc()
{


}


When i use this code in the .aspx page then it will work.. but i need it in the master page... Is there any way to use in master page...

Please help me sir....


Thanks in advance.

Dileep..
Posted
Updated 15-Aug-12 23:47pm
v3
Comments
Sergey Alexandrovich Kryukov 16-Aug-12 2:55am    
What exactly prevents you from doing it in a master page? Why you need it on the master page? Maybe you solution is somewhere else...
--SA
dilzz 16-Aug-12 3:01am    
Sir i have some other process in the master page,.. i need it in the master page, Is it possible to do it in the master page.?

1 solution

Try this

First add an Generic Handler For eg Test.ashx

C#
public class Test : IHttpHandler
{
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (context.Request.QueryString["input"] != null)
            {
                context.Response.Write("Test");
            }
        }
}


Then in your master page

JavaScript
$.ajax({
                type: 'post',
                url: 'Test.ashx?input=1',
                cache: false,
                error: function (xhr, status, errorthrown) {
                    alert(errorthrown + '\n' + status + '\n' + xhr.statustext);
                },
                success: function (html) {
                    alert(html);
                },
                datatype: 'html'
            });
 
Share this answer
 
Comments
dilzz 16-Aug-12 5:45am    
Thank you sir.. that is working.. But i need go back to master page .cs file.... i have a method in that master page .cs file.. Is there any way to re-direct "Generic Handler" to Master page Method..

Thanks,

Dileep
Renju Vinod 16-Aug-12 5:51am    
Hi Dileep,
Add that method into the handler

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900