accessing web method declared in .cs file not associated to any aspx or ascx file in ajax(jquery)

后端 未结 2 396
感动是毒
感动是毒 2021-01-22 16:40

Hi I moved a web method from code behind file of an aspx page to another cs file which is present in data section(which doesn\'t contain any aspx page). Previously I used to acc

相关标签:
2条回答
  • 2021-01-22 17:14

    They are called ASP.NET AJAX Page Methods for a reason, the endpoint must be public static methods, decorated with the WebMethod attribute, that are within a Page class or class that derives from Page.

    0 讨论(0)
  • 2021-01-22 17:15

    Try this

        var theWebRequest = HttpWebRequest.Create("http://localhost:51045/Default.aspx/Senddata");
                    theWebRequest.Credentials = new NetworkCredential(tobj.Username, tobj.Password,tobj.propertyID);
                    theWebRequest.Method = "POST";
                    theWebRequest.ContentType = "application/json; charset=utf-8 ";
                    //theWebRequest.Headers.Add(HttpRequestHeader.Pragma.ToString, "no-cache");
                    using (var writer = theWebRequest.GetRequestStream())
                    {
                        string json = new JavaScriptSerializer().Serialize(new
                        {
                            something = value                    
                        });
    
                        var data = Encoding.UTF8.GetBytes(json);
    
                        writer.Write(data, 0, data.Length);
                        writer.Flush();
                        writer.Close();
                    }
    
                    var theWebResponse = (HttpWebResponse)theWebRequest.GetResponse();         
                    var theResponseStream = new StreamReader(theWebResponse.GetResponseStream());
                    string result = theResponseStream.ReadToEnd().ToString();
       var data1 = new JavaScriptSerializer().DeserializeObject(result);
    
    0 讨论(0)
提交回复
热议问题