Calling WebMethod inside MasterPage using jQuery AJAX in ASP.Net

Last Reply 7 months ago By pandeyism

Posted 8 months ago

hi ,

i am using master page and want to execute webmethod of master page . but getting 404 not found error or 500 please check my code.

    <script src="" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            function calldata() {
                    type: "POST",
                    url: '<%=ResolveUrl("~/MainMdi.master/HelloWorld")%>' ,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                    error: function (xhr, ajaxOptions, thrownError) {
                return false;


    [System.Web.Script.Services.ScriptMethod(UseHttpGet = true)]
    public static string HelloWorld()
        return "Hello World";


Posted 8 months ago
Hi @Shahzad786,
Please try the following

[Solved] PageMethod not calling WebMethod when used in Master Page in ASP.Net

It might help you.

Cheers Andrea.

Posted 7 months ago

Hi Shahzad786,

You can't call WebMethod from master page. You need to write WebMethod in aspx page.

If you want multiple content pages be able to access the WebMethod, write your code in Web Service (ASMX) instead.