0

I have a simple ASP.NET webforms page with a button and a label. When using Safari 5.1.7 on Windows, clicking the button causes a postback, but does NOT actually cause the button click event to fire for some bizarre reason.

There are no javascript errors. There are no UpdatePanels or AJAX of any kind. This is literally the page I'm testing with:

<!doctype html>
<html lang="en">
<head runat="server">
    <meta charset="utf-8">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </form>
</body>
</html>

And the code behind is simply:

protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
    Label1.Text = "test";
}

When the button is clicked, the Page_Load event does fire one time, but Page.IsPostBack returns FALSE instead of true, and the Label1.Text is never set.

Note this problem ONLY happens in Safari. Everything works fine in IE8+, FF15+, Chrome 21+, and Opera 12+.

I've read numerous posts about Safari weirdness regarding hidden field size limitations (and therefore viewstate) - but this page should barely even be using viewstate (if at all). There are also many posts about javascript errors relating to UpdatePanels and/or AJAX calls, but as you can see there are none of those here.

I believe this question is also related, but I wanted to start a new one with example html/cs so you could reproduce the problem.

Am I missing something or is Safari on Windows really this weird?

Community
  • 1
  • 1
kman
  • 2,184
  • 3
  • 23
  • 42

1 Answers1

0

I cannot duplicate this in Safari 5.1.7. Can you provide more information on how you are binding your events? Your manual assignment of onclick="Button1_Click" implies you are doing manual event wire up. Does your page declaration match this?

Are you sure your Page_Load event is firing; your example has it empty.

Maybe a more verbose event binding is in order, the below worked for me:

ASPX test page:

<%@ Page Language="C#" AutoEventWireup="false" 
    CodeFile="default.aspx.cs" Inherits="PgSafari" %>
<!doctype html>
<html lang="en">
<head runat="server">
    <meta charset="utf-8">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">

        <div><asp:Literal runat="server" ID="litTimeStamp" EnableViewState="false" /></div>

        <div><asp:Button ID="Button1" runat="server" Text="Button" /></div>
        <div><asp:Label ID="Label1" runat="server" Text="Default Label Text" /></div>

        <div>
            <h6>Log:</h6>
            <asp:PlaceHolder runat="server" ID="plcOut" />
        </div>

    </form>
</body>
</html>

Code behind:

using System;
using System.Web.UI;

public partial class PgSafari : System.Web.UI.Page
{
    public PgSafari()
    {
        //Bind Page Events
        this.Init += new EventHandler(PgSafari_Init);
        this.Load += new EventHandler(PgSafari_Load);
    }

    protected void PgSafari_Init(object sender, EventArgs e)
    {
        Log("_Init()");

        //Bind Page Control Events
        Button1.Click += new EventHandler(Button1_Click);
    }

    protected void PgSafari_Load(object sender, EventArgs e)
    {
        Log("_Load()");
        Log("Page.IsPostBack = " + (Page.IsPostBack));

        litTimeStamp.Text = "TimeStamp: " + DateTime.Now.ToString("mm:ss.fff");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Log("Button1_Click()");
        Label1.Text = "test";
    }

    //===============\\

    private void Log(String msg)
    {
        plcOut.Controls.Add(new LiteralControl("<div>" + msg + "</div>"));
    }
}

The initial page hit in Safari looked like it should:
  TimeStamp: 58:44.452
  <button>
  Default Label Text
  Log:
  _Init()
  _Load()
  Page.IsPostBack = False

Clicking the it looked like it should also:
  TimeStamp: 59:48.869
  <button>
  TEST!
  Log:
  _Init()
  _Load()
  Page.IsPostBack = True
  Button1_Click()

cmd.prompt
  • 954
  • 7
  • 14
  • Thanks for the help, but it turned out to be the Negotiate provider in IIS. Removing that fixed it. See the referenced question for more details. – kman Oct 15 '12 at 14:16