I have a page with two DropDownLists and corresponding CascadingDropDown's. I want to automatically postback when the second DropDownList index changes, therefore I have set its AutoPostBack="true". I have wired up the web services and the lists are getting
populated as expected in IE7+, FireFox and Opera, but when I view the page in a WebKit based browsers (Chrome, Safari) the CascadingDropDown appear to load in an infinite loop. I included the
Webkit compatibility fix but the issue persists. I've attached a working example below.
Anyone know why Webkit browsers are infinitely reloading the cascading dropdownlists? Is there a fix?
if (typeof(Sys.Browser.WebKit) == "undefined") {
Sys.Browser.WebKit = {}; //Safari & Chrome are WebKit based browsers
}
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";
}
Code Behind:
Partial Class Default5
Inherits System.Web.UI.Page
Protected Sub ddlEventStatus_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
' Get a reference to the Event result DropDownList
Dim ddlEventStatus As DropDownList = CType(sender, DropDownList)
If ddlEventStatus IsNot Nothing Then
Me.lblStatus.Text = ddlEventStatus.SelectedItem.Text & " @ " & Now.ToString("h:mm:ss tt on dddd, MMMM d, yyyy")
End If
End Sub
End Class
Web Services Markup:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic
Imports AjaxControlToolkit
Imports System.Data
Imports System.Data.SqlClient
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _
Public Class CascadingDropDowns
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetEventTypeList(ByVal knownCategoryValues As String, ByVal category As String) As AjaxControlToolkit.CascadingDropDownNameValue()
Dim dtTypes As Data.DataTable = Nothing
Try
dtTypes = New Data.DataTable
dtTypes.Columns.Add(New Data.DataColumn("name", System.Type.GetType("System.String")))
dtTypes.Columns.Add(New Data.DataColumn("value", System.Type.GetType("System.Int32")))
Dim drType As Data.DataRow
drType = dtTypes.NewRow
drType.Item("value") = 0
drType.Item("name") = "Select Event Type"
dtTypes.Rows.InsertAt(drType, 0)
For i As Int32 = 1 To 10
drType = dtTypes.NewRow
drType.Item("value") = i
drType.Item("name") = i
dtTypes.Rows.Add(drType)
Next
Dim ProblemTypes As New List(Of CascadingDropDownNameValue)
For Each row As Data.DataRow In dtTypes.Rows
ProblemTypes.Add(New CascadingDropDownNameValue(row.Item("name").ToString, row.Item("value").ToString))
Next
Return ProblemTypes.ToArray
Catch ex As Exception
Return Nothing
Finally
If dtTypes IsNot Nothing Then dtTypes.Dispose()
dtTypes = Nothing
End Try
End Function
<WebMethod()> _
Public Function GetEventStatusList(ByVal knownCategoryValues As String, ByVal category As String, ByVal contextKey As String) As AjaxControlToolkit.CascadingDropDownNameValue()
Dim kv As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
Dim Event_Type_ID As String = Nothing
If (Not kv.ContainsKey("EventType")) OrElse (Not Int32.TryParse(kv("EventType"), Event_Type_ID)) Then
Return Nothing
End If
Dim dtResults As Data.DataTable = Nothing
Dim InitialValue As String = "Select Event Result"
Try
' Insert instruction row
If Event_Type_ID = 0 Then
InitialValue = "Select an Event Type first..."
End If
dtResults = New Data.DataTable
dtResults.Columns.Add(New Data.DataColumn("name", System.Type.GetType("System.String")))
dtResults.Columns.Add(New Data.DataColumn("value", System.Type.GetType("System.Int32")))
Dim drResult As Data.DataRow
drResult = dtResults.NewRow
drResult.Item("value") = 0
drResult.Item("name") = InitialValue
dtResults.Rows.InsertAt(drResult, 0)
If Event_Type_ID = 0 Then
Else
For i As Int32 = 1 To 10
drResult = dtResults.NewRow
drResult.Item("value") = i
drResult.Item("name") = """" & Event_Type_ID & """ - " & i
dtResults.Rows.Add(drResult)
Next
End If
Dim EventStatuses As New List(Of CascadingDropDownNameValue)
For Each row As Data.DataRow In dtResults.Rows
EventStatuses.Add(New CascadingDropDownNameValue(row.Item("name").ToString, row.Item("value").ToString))
Next
Return EventStatuses.ToArray
Catch ex As Exception
Return Nothing
Finally
If dtResults IsNot Nothing Then dtResults.Dispose()
dtResults = Nothing
End Try
End Function
End Class
I found a
tutorial (http://www.asp.net/learn/Ajax-Control-Toolkit/tutorial-17-vb.aspx) on this topic and was able to adapt a solution from it. Instead of using the javascript setAttribute
method I had to assign a function to the onchange event of my DropDownList to make the solution cross-browser compatible. Here are the modifications I made to the addAutoPostBack javascript function:
function pageLoad() {
addAutoPostBack();
} //end pageLoad
function addAutoPostBack() {
var objDdlEventStatus = null;
objDdlEventStatus = $get('<%= Me.ddlEventStatus.ClientID %>');
if (objDdlEventStatus) {
if (objDdlEventStatus.options.length > 0) {
objDdlEventStatus.onchange=function(){setTimeout("__doPostBack('"+this.id.replace(/_/g,"$")+"', '')",0);};
} else {
setTimeout("addAutoPostBack()", 250);
}
}
} //end addAutoPostBack
Marked as answer by celoftis on Jan 08, 2010 04:31 PM
celoftis
Member
56 Points
355 Posts
CascadingDropDown infinite reload loop in Webkit...
Jan 04, 2010 07:34 PM|LINK
Using VS2005, VB code behind,
I have a page with two DropDownLists and corresponding CascadingDropDown's. I want to automatically postback when the second DropDownList index changes, therefore I have set its AutoPostBack="true". I have wired up the web services and the lists are getting populated as expected in IE7+, FireFox and Opera, but when I view the page in a WebKit based browsers (Chrome, Safari) the CascadingDropDown appear to load in an infinite loop. I included the Webkit compatibility fix but the issue persists. I've attached a working example below.
Anyone know why Webkit browsers are infinitely reloading the cascading dropdownlists? Is there a fix?
Source code below:
Markup:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default5.aspx.vb" Inherits="Default5" EnableEventValidation="false" %> <!DOCTYPE html PUBLIC "-//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"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePageMethods="true" CombineScripts="True" ScriptMode="Release" EnablePartialRendering="True"> <Scripts> <asp:ScriptReference Path="~/Scripts/WebKit.js" /> </Scripts> </ajaxToolkit:ToolkitScriptManager> <asp:Label ID="lblStatus" runat="server" /><br /> <asp:DropDownList ID="ddlEventType" runat="server" /> <ajaxToolkit:CascadingDropDown ID="cddEventType" runat="server" TargetControlID="ddlEventType" Category="EventType" LoadingText="Loading event types..." ServicePath="~/Services/CascadingDropDowns.asmx" ServiceMethod="GetEventTypeList" /> <asp:DropDownList ID="ddlEventStatus" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlEventStatus_SelectedIndexChanged" /> <ajaxToolkit:CascadingDropDown ID="cddEventStatus" runat="server" TargetControlID="ddlEventStatus" ParentControlID="ddlEventType" Category="EventStatus" LoadingText="Loading event results..." ServicePath="~/Services/CascadingDropDowns.asmx" ServiceMethod="GetEventStatusList" UseContextKey="True" ContextKey="InitialEvent" /> </div> </form> </body> </html>Webkit.js
if (typeof(Sys.Browser.WebKit) == "undefined") { Sys.Browser.WebKit = {}; //Safari & Chrome are WebKit based browsers } 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"; }Code Behind:
Partial Class Default5 Inherits System.Web.UI.Page Protected Sub ddlEventStatus_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) ' Get a reference to the Event result DropDownList Dim ddlEventStatus As DropDownList = CType(sender, DropDownList) If ddlEventStatus IsNot Nothing Then Me.lblStatus.Text = ddlEventStatus.SelectedItem.Text & " @ " & Now.ToString("h:mm:ss tt on dddd, MMMM d, yyyy") End If End Sub End ClassWeb Services Markup:
Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.Collections.Generic Imports AjaxControlToolkit Imports System.Data Imports System.Data.SqlClient <WebService(Namespace:="http://tempuri.org/")> _ <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ <System.Web.Script.Services.ScriptService()> _ Public Class CascadingDropDowns Inherits System.Web.Services.WebService <WebMethod()> _ Public Function GetEventTypeList(ByVal knownCategoryValues As String, ByVal category As String) As AjaxControlToolkit.CascadingDropDownNameValue() Dim dtTypes As Data.DataTable = Nothing Try dtTypes = New Data.DataTable dtTypes.Columns.Add(New Data.DataColumn("name", System.Type.GetType("System.String"))) dtTypes.Columns.Add(New Data.DataColumn("value", System.Type.GetType("System.Int32"))) Dim drType As Data.DataRow drType = dtTypes.NewRow drType.Item("value") = 0 drType.Item("name") = "Select Event Type" dtTypes.Rows.InsertAt(drType, 0) For i As Int32 = 1 To 10 drType = dtTypes.NewRow drType.Item("value") = i drType.Item("name") = i dtTypes.Rows.Add(drType) Next Dim ProblemTypes As New List(Of CascadingDropDownNameValue) For Each row As Data.DataRow In dtTypes.Rows ProblemTypes.Add(New CascadingDropDownNameValue(row.Item("name").ToString, row.Item("value").ToString)) Next Return ProblemTypes.ToArray Catch ex As Exception Return Nothing Finally If dtTypes IsNot Nothing Then dtTypes.Dispose() dtTypes = Nothing End Try End Function <WebMethod()> _ Public Function GetEventStatusList(ByVal knownCategoryValues As String, ByVal category As String, ByVal contextKey As String) As AjaxControlToolkit.CascadingDropDownNameValue() Dim kv As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues) Dim Event_Type_ID As String = Nothing If (Not kv.ContainsKey("EventType")) OrElse (Not Int32.TryParse(kv("EventType"), Event_Type_ID)) Then Return Nothing End If Dim dtResults As Data.DataTable = Nothing Dim InitialValue As String = "Select Event Result" Try ' Insert instruction row If Event_Type_ID = 0 Then InitialValue = "Select an Event Type first..." End If dtResults = New Data.DataTable dtResults.Columns.Add(New Data.DataColumn("name", System.Type.GetType("System.String"))) dtResults.Columns.Add(New Data.DataColumn("value", System.Type.GetType("System.Int32"))) Dim drResult As Data.DataRow drResult = dtResults.NewRow drResult.Item("value") = 0 drResult.Item("name") = InitialValue dtResults.Rows.InsertAt(drResult, 0) If Event_Type_ID = 0 Then Else For i As Int32 = 1 To 10 drResult = dtResults.NewRow drResult.Item("value") = i drResult.Item("name") = """" & Event_Type_ID & """ - " & i dtResults.Rows.Add(drResult) Next End If Dim EventStatuses As New List(Of CascadingDropDownNameValue) For Each row As Data.DataRow In dtResults.Rows EventStatuses.Add(New CascadingDropDownNameValue(row.Item("name").ToString, row.Item("value").ToString)) Next Return EventStatuses.ToArray Catch ex As Exception Return Nothing Finally If dtResults IsNot Nothing Then dtResults.Dispose() dtResults = Nothing End Try End Function End ClassCascading dropdown Webkit loop
celoftis
Member
56 Points
355 Posts
Re: CascadingDropDown infinite reload loop in Webkit...
Jan 05, 2010 03:17 PM|LINK
Anyone?
celoftis
Member
56 Points
355 Posts
Re: CascadingDropDown infinite reload loop in Webkit...
Jan 06, 2010 02:41 PM|LINK
I'm really stuck on this. Can anyone suggest a workaround?
celoftis
Member
56 Points
355 Posts
Re: CascadingDropDown infinite reload loop in Webkit...
Jan 08, 2010 04:30 PM|LINK
I found a tutorial (http://www.asp.net/learn/Ajax-Control-Toolkit/tutorial-17-vb.aspx) on this topic and was able to adapt a solution from it. Instead of using the javascript setAttribute method I had to assign a function to the onchange event of my DropDownList to make the solution cross-browser compatible. Here are the modifications I made to the addAutoPostBack javascript function:
function pageLoad() { addAutoPostBack(); } //end pageLoad function addAutoPostBack() { var objDdlEventStatus = null; objDdlEventStatus = $get('<%= Me.ddlEventStatus.ClientID %>'); if (objDdlEventStatus) { if (objDdlEventStatus.options.length > 0) { objDdlEventStatus.onchange=function(){setTimeout("__doPostBack('"+this.id.replace(/_/g,"$")+"', '')",0);}; } else { setTimeout("addAutoPostBack()", 250); } } } //end addAutoPostBackbk123456789
Member
2 Points
1 Post
Re: CascadingDropDown infinite reload loop in Webkit...
Jul 25, 2011 04:29 PM|LINK
[Post deleted]