1

In IE, when I call a page method from the OnPaste event, I get the following error when I click on the input box and hit CTRL+V:

0x80070057 - JavaScript runtime error: Invalid argument.

at this line of code:

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

The call stack looks like this:

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

I've reproduced it in a small project. Here's 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>

Here's 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!";
        }
    }
}

I've called the same Page Method from the OnBlur event and when you tab out of the input box, it works fine. This OnPaste event calling PageMethod works fine in Chrome. Is there some difference in the context of an OnPaste event for IE vs most other events?

Thanks.

daniele3004
  • 13,072
  • 12
  • 67
  • 75
ariscris
  • 533
  • 1
  • 4
  • 19
  • Using IE 11, this seemed to work fine. What version of IE are you using? Possibly its conflicting with an addon? – Icemanind Oct 03 '14 at 18:30
  • Duplicate? If I use a `setTimeout` as outlined in [this question](http://stackoverflow.com/q/23426632/497356) the issue goes away. – Andrew Whitaker Oct 03 '14 at 18:58
  • @icemanind, IE 11. I'll see if there are add-ons that may be causing this. – ariscris Oct 04 '14 at 18:44
  • @AndrewWhitaker, I'll try it on Monday and let you know if it works, thanks. – ariscris Oct 04 '14 at 18:46
  • @AndrewWhitaker, thanks that worked. What should I do next, mark this as duplicate? Give you the bounty? – ariscris Oct 06 '14 at 13:18
  • @ariscris: I'm actually not sure. It seems wrong to "waste" the bounty ,but it at the same time it *is* a duplicate... – Andrew Whitaker Oct 06 '14 at 13:20
  • @AndrewWhitaker, I tried flagging for this question to be marked as duplicate 2 days ago but nothing has happened. Can you just add an answer so that I can award you the bounty? It might as well go to someone and I can earn a badge. Thanks. – ariscris Oct 08 '14 at 15:54
  • @ariscris: Sure, that sounds fine. I'll add an answer. We can close the question after the bounty expires. – Andrew Whitaker Oct 08 '14 at 15:57

1 Answers1

2

Not sure exactly what's happening, but the symptoms are the same as the issue described in this question. Some problem with IE combined with the onpaste event, combined with making an AJAX request.

I was able to get rid of the problem by using setTimeout with a small delay:

function GetMessage() {
    setTimeout(function () {
        PageMethods.Message(OnGetMessageSuccess, OnGetMessageFailure);
    }, 100);
}
Community
  • 1
  • 1
Andrew Whitaker
  • 124,656
  • 32
  • 289
  • 307