Asp.net动态验证器不会在Chrome或Safari工作 [英] Asp.net Dynamic Validators don't work in Chrome or Safari

查看:346
本文介绍了Asp.net动态验证器不会在Chrome或Safari工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我动态创建Asp.net验证控件,并将其插入到一个更新面板。验证工作在IE和Firefox,但不是在Chrome或Safari。

Ok, I'm dynamically creating Asp.net validation controls and inserting them into an update panel. The validation works in IE and Firefox, but not in Chrome or Safari.

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

Here is the aspx file. Don't ask why I'm not using a button server control...

 <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>

下面是code背后:

 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的工作任何想法?

Does anyone have any ideas on how to get this to work in Chrome and Safari?

推荐答案

ASP.NET AJAX默认情况下不使用Safari玩好。它有几个JavaScript的黑客在里面,使其与Safari浏览器1.x的不再需要的工作。不幸的是,这打破AJAX Safari的3.但是,有一个解决方案。

ASP.NET AJAX doesn't play well with Safari by default. It has several JavaScript hacks in it to make it work with Safari 1.x that are no longer needed. Unfortunately, this breaks AJAX for Safari 3. But, there is a solution.

创建一个 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这样的:

Then define your ScriptManager like this:

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

我不知道关于Chrome。我没有ASP.NET AJAX问题,它为止。这是pretty傻,微软并没有解决这一问题的.NET 3.5 SP1最少,但你可以做什么:(

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 :(

这篇关于Asp.net动态验证器不会在Chrome或Safari工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆