【问题标题】:Cannot call a Page Method from the OnPaste event无法从 OnPaste 事件调用页面方法
【发布时间】:2014-10-08 23:59:42
【问题描述】:

在 IE 中,当我从 OnPaste 事件中调用页面方法时,单击输入框并按 CTRL+V 时出现以下错误:

0x80070057 - JavaScript runtime error: Invalid argument.

在这行代码:

this._xmlHttpRequest.open(verb, this._webRequest.getResolvedUrl(), true );

调用堆栈如下所示:

Sys$Net$XMLHttpExecutor$executeRequest [ScriptResource.axd] Line 6055   Script
Sys$Net$_WebRequestManager$executeRequest [ScriptResource.axd] Line 6302    Script
Sys$Net$WebRequest$invoke [ScriptResource.axd] Line 6481    Script
Sys$Net$WebServiceProxy$invoke [ScriptResource.axd] Line 6923   Script
Sys$Net$WebServiceProxy$_invoke [ScriptResource.axd] Line 6807  Script
PageMethods.prototype.Message [WebForm1.aspx] Line 76   Script
PageMethods.Message [WebForm1.aspx] Line 117    Script
GetMessage [WebForm1.aspx] Line 11  Script
onpaste [WebForm1.aspx] Line 125    Script

我已经在一个小项目中复制了它。这是 WebForm1.aspx:

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type='text/javascript'>
        function GetMessage() {
            PageMethods.Message(OnGetMessageSuccess, OnGetMessageFailure);
        }
        function OnGetMessageSuccess(result, userContext, methodName) {
            alert(result);
        }
        function OnGetMessageFailure(error, userContext, methodName) {
            alert(error.get_message());
        }
    </script>

</head>
<body>
    <form id='form1' runat='server'>
        <input value="paste here" onpaste="GetMessage()" onblur="GetMessage()" />
        <asp:ScriptManager ID='ScriptManager1' runat='server' EnablePageMethods='true' />
        <div>
            <input type='submit' value='Get Message' onclick='GetMessage(); return false;' />
        </div>
    </form>
</body>
</html>

这里是 WebForm1.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PageMethodTest
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        [System.Web.Services.WebMethod]
        public static string Message()
        {
            return "Hello from the server-side World!";
        }
    }
}

我从 OnBlur 事件中调用了相同的页面方法,当您从输入框跳出时,它工作正常。这个调用 PageMethod 的 OnPaste 事件在 Chrome 中运行良好。 IE 的 OnPaste 事件的上下文与大多数其他事件的上下文是否存在一些差异?

谢谢。

【问题讨论】:

  • 使用 IE 11,这似乎工作正常。你用的是什么版本的IE?可能与插件冲突?
  • 重复?如果我使用this question 中所述的setTimeout,问题就会消失。
  • @icemanind,IE 11。我会看看是否有可能导致此问题的附加组件。
  • @AndrewWhitaker,我会在星期一试一试,如果它有效,请告诉你,谢谢。
  • @AndrewWhitaker,谢谢你的工作。接下来我该怎么做,将其标记为重复?给你赏金?

标签: c# asp.net .net internet-explorer pagemethods


【解决方案1】:

不确定确切发生了什么,但症状与this question 中描述的问题相同。 IE 的一些问题与onpaste 事件相结合,结合发出 AJAX 请求。

我可以通过使用setTimeout 来解决这个问题,但会有一点延迟:

function GetMessage() {
    setTimeout(function () {
        PageMethods.Message(OnGetMessageSuccess, OnGetMessageFailure);
    }, 100);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-17
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多