Calling WebMethod inside MasterPage using jQuery AJAX in ASP.Net

Last Reply 6 months ago By pandeyism

Posted 7 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";


You are viewing reply posted by: pandeyism 6 months ago.
Posted 6 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.