Asp.net dynamic validators do not work in Chrome or Safari

Ok, I dynamically create Asp.net validation controls and paste them into the update panel. Validation is done in IE and Firefox, but not in Chrome or Safari.

Here is the aspx file. Do not ask why I do not use the control button on the button ...

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

Here is the code behind:

  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 

And here is the class:

  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 

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

+4
source share
1 answer

ASP.NET AJAX does not work with Safari by default. It has several JavaScript hackers to work with Safari 1.x, which are no longer needed. Unfortunately, this violates AJAX for Safari 3. But there is a solution.

Create Safari3AjaxHack.js , for example:

 // 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'; } 

Then define your ScriptManager as follows:

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

I'm not sure about Chrome. So far I have not had ASP.NET AJAX issues. It's pretty stupid that Microsoft did not fix this in .NET 3.5 SP1 at least, but what you can do: (

+8
source

All Articles