Different Behavior Between IE, FireFox, and Safari with a PageMethod

Last post 11-04-2009 5:04 AM by imran_ku07. 9 replies.

Sort Posts:

  • Different Behavior Between IE, FireFox, and Safari with a PageMethod

    04-03-2009, 3:11 PM
    • Member
      point Member
    • pianoman1962
    • Member since 04-03-2009, 6:17 PM
    • Posts 4

     I hope this is the correct location for this post; if not I apologize...I have an AJAX web form with a hyperlink and an asp button.  The hyperlink uses the onclick event to call a javascript function while the asp button calls the same javascript function in the onclientclick event. The button uses the postbackurl to post back to another site.  The javascript function in turn calls a pagemethod.

    My problem is the call to the pagemethod only works successfully with IE but not FireFox or Safari.   Any help is appreciated; my code is below: 

    ASPX Code
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PageMethodExperiment._Default" EnableSessionState="ReadOnly" %>

    "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="
    http://www.w3.org/1999/xhtml" >
    "server">
    Untitled Page

    "text/javascript" language="javascript"> function JScriptTest() { // alert('before'); PageMethods.TestPageMethod('passed this text',onSuccess, onFailure); // alert('after'); } function onSuccess(result) { // alert('successful'); alert(result); } function onFailure(result) { alert('failed'); alert(result.get_message()); }

    "form1" runat="server">
    "ScriptManager1" EnablePageMethods="true" runat="server" />



    "Button1" runat="server" Style="z-index: 100; left: 125px; position: absolute;
    top: 160px"
    Text="Button" OnClientClick="return JScriptTest();" PostBackUrl="http://www.sequencesoftware.com" />
    <a href="
    #" onclick="JScriptTest();" id="test"&gt;hyper link</a>
    </form>
    </body>
    </html>

    ASPX.CS
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Web.Services;

    namespace PageMethodExperiment
    {
    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [WebMethod]
    public static string TestPageMethod(string inputString)
    {
    return "
    Hello world - " + inputString;
    }
    }
    }
     
  • Re: Different Behavior Between IE, FireFox, and Safari with a PageMethod

    04-03-2009, 6:41 PM
    • Star
      13,605 point Star
    • gt1329a
    • Member since 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 2,248
    • ASPInsiders
      TrustedFriends-MVPs

    I'm not sure if you're going to get the behavior you want, making an asynchronous call at the same time that you're navigating away from the page with the Button.

    However, to resolve the differences between browsers, try removing the language="javascript" attribute from your script tag.  That's an HTML 4 attribute, but you've declared XHTML in your doctype.  This discrepancy might be handled differently cross-browser.

    Encosia - ASP.NET, jQuery, AJAX, and more.

    Latest article: Emulate ASP.NET validation groups with jQuery validation
  • Re: Different Behavior Between IE, FireFox, and Safari with a PageMethod

    04-03-2009, 11:08 PM
    • Member
      point Member
    • pianoman1962
    • Member since 04-03-2009, 6:17 PM
    • Posts 4

    Unfortunately your suggestion did not work.  I don't understand doctype that well but could changing this help?  My example just used the default doctyp from Vs2005.

  • Re: Different Behavior Between IE, FireFox, and Safari with a PageMethod

    11-03-2009, 8:52 AM
    • Member
      4 point Member
    • balmeter
    • Member since 11-03-2009, 1:50 PM
    • Posts 2

    Did you come up with a solution for this is Firefox? I am banging my head over it.

    My PageMethod works in IE but not in Firefox 

    Filed under: ,
  • Re: Different Behavior Between IE, FireFox, and Safari with a PageMethod

    11-03-2009, 3:15 PM
    • Member
      point Member
    • pianoman1962
    • Member since 04-03-2009, 6:17 PM
    • Posts 4

    Unfortunately I did not find an answer. 

  • Re: Different Behavior Between IE, FireFox, and Safari with a PageMethod

    11-03-2009, 3:39 PM
    • Member
      4 point Member
    • balmeter
    • Member since 11-03-2009, 1:50 PM
    • Posts 2

    Thanks for answering. This is driving me nuts. I found the code works in Firefox IF i step through the code in Firebug. Really weird. 

  • Re: Different Behavior Between IE, FireFox, and Safari with a PageMethod

    11-03-2009, 4:30 PM
    • Star
      13,605 point Star
    • gt1329a
    • Member since 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 2,248
    • ASPInsiders
      TrustedFriends-MVPs

    I believe the first part of my original answer was correct.

    That Button control submits the form, which results in a reload of the page occuring at about the same time as the AJAX request, making it seem like the AJAX request didn't work right.  The link doesn't, because the "#" href doesn't trigger a full navigation event (just an on-page jump if the anchor you name exists).

    If you change the OnClientClick to "JScriptTest(); return false;", it should work as you intended.

    More ideally, you should wire the event up unobtrusively, using $addHandler (and preventDefault to stop the form submission).

    Encosia - ASP.NET, jQuery, AJAX, and more.

    Latest article: Emulate ASP.NET validation groups with jQuery validation
  • Re: Different Behavior Between IE, FireFox, and Safari with a PageMethod

    11-03-2009, 4:31 PM
    • Member
      point Member
    • pianoman1962
    • Member since 04-03-2009, 6:17 PM
    • Posts 4

    I found that too. It appears to be related to how long events take and/or the order which may vary between IE and other browsers.  Stepping through affects timing but in production will not work.   

  • Re: Different Behavior Between IE, FireFox, and Safari with a PageMethod

    11-03-2009, 4:34 PM
    • All-Star
      62,799 point All-Star
    • TATWORTH
    • Member since 02-04-2003, 1:34 PM
    • England
    • Posts 12,252
    • TrustedFriends-MVPs

    A couple of suggestions:

    • Validate your rendered HTML using the W3C XHTML tests at http://validator.w3.org/
    • Study the HTML rendered to each of the browsers to check that it is being emitted as expected.
    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Different Behavior Between IE, FireFox, and Safari with a PageMethod

    11-04-2009, 5:04 AM
    • All-Star
      17,455 point All-Star
    • imran_ku07
    • Member since 06-04-2008, 9:21 AM
    • KARACHI, PAKISTAN
    • Posts 3,188

    Interesting, your code is working in SAFARI, FF, IE,OPERA and Chrome in my machine,

    i have only add return false in your function,

    function JScriptTest()
        {   
            PageMethods.TestPageMethod('passed this text',onSuccess, onFailure);    
            return false;

        }

    is your web.config contains xhtmlconformance,

    http://weblogs.asp.net/scottgu/archive/2006/12/10/gotcha-don-t-use-xhtmlconformance-mode-legacy-with-asp-net-ajax.aspx

Page 1 of 1 (10 items)