4

好的,我正在动态创建 Asp.net 验证控件并将它们插入到更新面板中。验证在 IE 和 Firefox 中有效,但在 Chrome 或 Safari 中无效。

这是aspx文件。不要问我为什么不使用按钮服务器控件...

 <asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <asp:UpdatePanel ID="UpdatePanel1"  UpdateMode="Always" runat="server">
    <ContentTemplate>

        <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
        <input id="Button1" type="button" value="submit" onclick='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("Button1", "btnNext", true, "", "", false, true))' />

    </ContentTemplate>

</asp:UpdatePanel>

</div>

这是后面的代码:

 Dim Survey As New Survey

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Request("__EVENTARGUMENT") = "btnNext" Then
        NextClick()
    End If

    Label1.Text = Date.Now.ToString



End Sub

Private Sub NextClick()
    Survey.RenderPage(PlaceHolder1)
End Sub

这是课程:

    Public Class Survey

    Public Sub RenderPage(ByVal PlaceHolder As PlaceHolder)

        Dim textbox As New TextBox
        textbox.ID = "testing"
        PlaceHolder.Controls.Add(textbox)

        Dim val As New RequiredFieldValidator
        val.ControlToValidate = textbox.ID
        val.Text = "required"
        val.EnableClientScript = True
        PlaceHolder.Controls.Add(val)

    End Sub
End Class

有没有人知道如何让它在 Chrome 和 Safari 中工作?

4

1 回答 1

8

默认情况下,ASP.NET AJAX 不能很好地与 Safari 配合使用。它有几个 JavaScript hack,使它与不再需要的 Safari 1.x 一起工作。不幸的是,这破坏了 Safari 3 的 AJAX。但是,有一个解决方案。

创建一个Safari3AjaxHack.js,像这样:

// Safari 3 AJAX "issue". It no longer needs JavaScript hacks that are still implemented
// http://forums.asp.net/p/1252014/2392110.aspx

Sys.Browser.WebKit = {}; //Safari 3 is considered WebKit
if (navigator.userAgent.indexOf('WebKit/') > -1) {
    Sys.Browser.agent = Sys.Browser.WebKit;
    Sys.Browser.version = parseFloat(
        navigator.userAgent.match(/WebKit\/(\d+(\.\d+)?)/)[1]);
    Sys.Browser.name = 'WebKit';
}

然后像这样定义你的 ScriptManager:

<asp:ScriptManager runat="server" ID="ScriptManager1">
    <Scripts>
        <asp:ScriptReference Path="~/Scripts/Safari3AjaxHack.js" />
    </Scripts>      
</asp:ScriptManager>

I'm not sure about Chrome. I haven't had ASP.NET AJAX problems with it so far. It's pretty silly that Microsoft didn't fix this in .NET 3.5 SP1 at least, but what can you do :(

于 2009-08-07T21:23:01.257 回答