locked
PageMethods not working if the website is created as a Visual C# ASP.Net Web Application in VS2015 RRS feed

  • Question

  • I am a newbie in web developing with VS (Visual Studio). I have the following problem and would appreciate it very much if you could share your view on this.

    PROBLEM: PageMethods works OK if I create a new website in VS via [File] - [New Web Site] - [ASP.NET Empty Web Site] as per the files given below. But if I create a new website in VS via [File] - [New Project] - [Visual C# ASP.NET Web Application] then PageMethods do NOT work as per the files given below. Moreover, I can not run any method created in aspx.cs files!

    Obviously, I am missing a basic step/concept but I can not see it unfortunately!

    ASPX File:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test4.aspx.cs" Inherits="ETDBWebApplication1.Content.Test.Test4" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="~/Scripts/jquery-3.5.1.js"></script>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager runat="server" ID="sm1" EnablePageMethods="true" />
            <div>
                <script type="text/javascript">
                    function getValues() {
                        var text1 = $('#txt1').val();
                        PageMethods.GetValues(text1, getValues_Success, getValues_Fail);
                    }
                    function getValues_Success(msg){
                        $('#div1').html(msg);
                    }
                    function getValues_Fail(msg) {
                        alert(msg.get_message());
                    }
                </script>
                <input type="text" id="txt1" />
                <br />
                <input type="button" onclick="getValues();" value="get values"/>
                <br />
                <br />
                <div id="div1"></div>
            </div>
        </form></body>
    </html>
    

    • Moved by CoolDadTx Monday, June 1, 2020 8:49 PM ASP.NET related
    Monday, June 1, 2020 2:41 PM

All replies

  • ASPX.CS FILE (CODEBEHIND):

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace ETDBWebApplication1.Content.Test
    {
        public partial class Test4 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            [WebMethod]
            public static string GetValues(string value)
            {
                value = value + DateTime.UtcNow.ToLongTimeString();
                return value;
            }
        }
    }
    Monday, June 1, 2020 2:42 PM
  • ASP.NET can be discussed at the ASP.NET forums.

    http://forums.asp.net/

    Monday, June 1, 2020 2:58 PM
  • Many thanks.
    Monday, June 1, 2020 8:46 PM