Click here to Skip to main content
15,885,213 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I've tried to access a webmethod from a Master Page in asp.net using jQuery ajax. A folder named 'Module' holds the master page. All the other child pages reside under the subfolder on the 'Module' folder. I've written an ajax post code in the maste page like below
C#
var GetNotification = function () {
                 $.ajax({
                type: 'POST',
                url: 'MyTest.Master/Test',
                async: false,
                cache: true,
                dataType: 'json',
                contentType: 'application/json;charset=utf-8',
                data: '{}',
                success: function (data) {
                    alert(data.d);
                },
                error: function (request, status, error) {
                    alert(request.responseText);
                }
            });
        }

if I enter into the Home page its path will be on Modules/Home. But my webmethod is on the 'Modules/MyTest.Master/Test'. I cant navigate to the webmethod's correct url. Can you please help me.
Posted
Updated 19-Aug-14 21:05pm
v3

Please wrote that webmethod in a aspx.cs page and provide the url as 'somefolder/youraspxpage.aspx/yourmethodname'
 
Share this answer
 
Hi,

try to put your method in a page.aspx not in the master templage
C#
url: 'MyTest.aspx/Test',

Because url does not detect MyTest.Master . I mean .master extention
 
Share this answer
 
v2
Comments
Libin C Jacob 20-Aug-14 3:21am    
Hi,
My problem is because of the master page is out side all the pages folder. So every time the path will be the current page's.
[no name] 20-Aug-14 3:37am    
so use webservice class for this and define your method there and call your webservice class name with your method name....
something this way

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