标签: webmethod

Webmethod 引发“无法从共享方法或共享成员中引用类的实例成员...”

我有以下网络方法

<System.Web.Services.WebMethod()> Public Shared Function NewMethod(ByVal str1 As String) As String
  LoadBlock(str1)
  Return "Success"
End Function
Run Code Online (Sandbox Code Playgroud)

以及以下程序

Public Sub LoadBlock(ByVal AA As Integer)
  panAway.Visible = False '<--ASP panel control
  lblHome.Visible = False '<--ASP label control
End
Run Code Online (Sandbox Code Playgroud)

这会引发以下错误

Cannot refer to an instance member of a class from within a shared method or 
shared member initializer without an explicit instance of the class.
Run Code Online (Sandbox Code Playgroud)

我知道我收到以下错误,因为我尚未将 LoadBlock 设置为共享

但是如果我这样做了我的程序中的所有控件......会引发上面的错误

我能做些什么吗?

vb.net asp.net asmx pagemethods webmethod

2
推荐指数
1
解决办法
4196
查看次数

如何调用母版页的web方法?

Jquery/Javascript:想要在 notification_count_span 淡出并返回 false 后调用 updateNotification() 函数。Web 方法位于母版页中。

<script type="text/javascript" >
    $(document).ready(function () {
        $("#notificationLink").click(function () {
            $("#notificationContainer").fadeToggle(300);
            $("#notification_count_span").fadeOut("slow");
            return false;
            // updateNotification()
        });

        //Document Click
        $(document).click(function () {
            $("#notificationContainer").hide();
        });
    });
    function updateNotification() {
        $.ajax({
            type: "POST",
            url: "SiteMaster.master/UpdateNotification",
            data: '{nForId: "' + $("#<%=sessionUnameHf.ClientID%>")[0].value + '" }',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                //alert(msg.d)
                //do nothing
            }
        });
    }
</script>
Run Code Online (Sandbox Code Playgroud)

HTML母版页中的 Html 代码。

 <asp:Label ID="notification_count_lbl" runat="server" Text=""></asp:Label></span>
            <asp:LinkButton ID="notificationLink" runat="server">Notifications</asp:LinkButton>
<!--<a href="#" id="notificationLink1" runat="server" …
Run Code Online (Sandbox Code Playgroud)

javascript asp.net jquery webmethod

2
推荐指数
1
解决办法
9012
查看次数

什么是Web服务中的Web方法属性?

什么是Web服务中的Web方法属性?举个例子

[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true)]
public string GetApplicationDomains(string strParameterList)
{

}        
Run Code Online (Sandbox Code Playgroud)

为什么使用WebMethod和ScriptMethod这个属性?

c# asp.net web-services webmethod

1
推荐指数
1
解决办法
2万
查看次数

ASP.NET 4 jquery ajax webmethod调用

在ASP.NET 3.5中,我在页面上有这个javascript(default.aspx):

function getMoreNewsItems() {
    $.ajax({
        type: "POST",
        url: "default.aspx/LoadNewsItems",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            alert(msg.d);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

在后面的代码中使用这个(default.aspx.cs):

[System.Web.Services.WebMethod]
public static string LoadNewsItems() {
    return "test1";
}
Run Code Online (Sandbox Code Playgroud)

我在页面上有一个ScriptManagerMethods = true的ScriptManager.一切正常.

现在项目升级到ASP.NET 4.0并使用新的URL路由功能.AJAX调用不再起作用.在FireBug中,我看到它返回完整的页面,而不是XML响应.

ASP.NET 4中可能导致此错误的变化是什么?

ajax jquery asp.net-4.0 webmethod

1
推荐指数
1
解决办法
3942
查看次数

从WebMethod返回要在jQuery中使用的多个值

我有jquery使用ajax/json来获取元素ID,然后点击:

[System.Web.Services.WebMethod]
public static string EditPage(string nodeID)
{
    DataTable dt = new DataTable();
    using (SqlConnection con = new SqlConnection(Global.conString))
    using (SqlCommand cmd = new SqlCommand("contentPageGetDetail", con))
    {
        cmd.Parameters.Add("@ID", SqlDbType.UniqueIdentifier).Value = Global.SafeSqlLiteral(nodeID, 1);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.ExecuteNonQuery();
        using (SqlDataAdapter da = new SqlDataAdapter(cmd))
        {
            da.Fill(dt);
        }
    }
    if (dt.Count > 0)
    {
      string pageTitle = dt.Rows[0]["Title"].toString();
      string contentID = dt.Rows[0]["ContentID"].toString();
      return pageTitle, contentID, nodeID;
    }
    else
    {
      return "Failed";
    }
}
Run Code Online (Sandbox Code Playgroud)

当返回时,我想从存储过程返回的所有内容返回到成功部分中的jquery方法,并在文本字段中设置隐藏字段,下拉值和标题.

在jQuery中我尝试使用"pageTitle",但它未定义.我需要做什么jQuery方面来获取返回的内容并在显示表单之前填充Web窗体中的字段?

c# asp.net ajax jquery webmethod

1
推荐指数
1
解决办法
9916
查看次数

jQuery AJAX调用ASP.NET WebMethod

我有以下jQuery AJAX请求:

function sendUpdate(urlToSend) {
    var code = AccessCode; 
    var url = urlToSend;
    var options = { error: function(msg) { alert(msg.d); },
                    type: "POST", url: "webmethods.aspx/UpdatePage",
                    data: "{ accessCode: " + code + ", newURL: '" + url + "' }",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true, 
                    success: function(response) { var results = response.d; } }; 
    $.ajax(options);
}
Run Code Online (Sandbox Code Playgroud)

和相应的ASP.NET WebMethod:

[WebMethod]
public static bool UpdatePage(string accessCode, string newURL)
{
    bool result = true;
    try
    {
        HttpContext.Current.Cache[accessCode + "l"] = …
Run Code Online (Sandbox Code Playgroud)

c# ajax jquery webmethod

1
推荐指数
1
解决办法
4万
查看次数

什么是网络方法

Web方法究竟是什么?它是一种语言,框架或应用程序,还是纯粹是负责应用程序集成的公司,即提供实现集成的框架.

请简要介绍一下.谢谢

webmethod web

1
推荐指数
1
解决办法
8651
查看次数

调用的WebMethod与参数从jQuery的阿贾克斯失败

我对以下问题感到困惑.

我有一个"WebForm1.aspx的"和"WebService1.asmx".当我在WebService WITHOUT参数('HelloWorld')中调用WebMethod时,它工作正常.当我调用Method WITH参数('SayHello')时,它失败了.

它甚至没有命中方法(我没有达到方法中设置的断点).xmlHttpRequest错误是"内部服务器错误"

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

    [WebMethod]
    public string SayHello(string firstName, string lastName)
    {
        return "Hello " + firstName + " " + lastName;
    }
}
Run Code Online (Sandbox Code Playgroud)



我WebForms1.aspx:

    <div><br />No Parameters </div>
<div id="NoParameters"></div>
<div><br />With Parameters</div>
<div id="WithParameters"></div>


<script type="text/javascript"> …
Run Code Online (Sandbox Code Playgroud)

ajax jquery webforms webmethod

1
推荐指数
1
解决办法
2万
查看次数

我可以在C#WebMethod中更改参数名称吗?

C#WebMethod是否可以接受与其客户端发送的不同的参数名称?

例如,给定客户端发送此消息:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <GetStatus xmlns="http://example.com/">
            <Arg1>5</Arg1>
            <Arg2>3</Arg2>
        </GetStatus>
    </soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)

是否可以重写现有的WebMethod以适应不同的参数名称?像这样的东西?

[WebMethod]
public string GetStatus(
    [MessageParameter(Name = "Arg1")] string orderId, 
    [MessageParameter(Name = "Arg2")] string typeId)
Run Code Online (Sandbox Code Playgroud)

.net parameters asmx webmethod

1
推荐指数
1
解决办法
1421
查看次数

从jquery C#调用webmethod在.net aspx页面中返回404错误

必须遗漏一些基本的东西.我在本地运行的aspx页面中从jquery调用web方法时遇到404错误.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="empJquery.aspx.cs" Inherits="webApiOracle.empJquery" %>

<!DOCTYPE html>

<html lang="en">
<head runat="server">
    <title>jquery emps</title>
    <script src="Scripts/jquery-1.10.2.min.js"></script>
    <link href="../Content/bootstrap.min.css" rel="stylesheet" />
    <script type="text/javascript">


        $(document).ready(function () {
            getEmployees();

        });

        function getEmployees() {
            jQuery.ajax({
                url: 'empJquery.aspx/Test',
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: function () {
                    alert("Start!!! ");
                },
                success: function (data) {
                    alert("a");
                },
                error: function (msg) { alert("Sorry!!! "); }

            });
        }

    </script>
Run Code Online (Sandbox Code Playgroud)

然后在代码页面后面

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using webApiOracle.Models; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net jquery webmethod

1
推荐指数
1
解决办法
3300
查看次数