Saturday, March 24, 2012

Internet Explorer freezes after using AJAX

Hi

I have a weird problem. I have created an ASP.NET site which is displayed as a popup in another website.
The popup shows a treeview with which the user can update some data via an webservice. After selecting a treenode, a webservice is called in the code behind.
When I open this popup two times it will freeze all Internet Explorer windows which belongs to the current website. Only restarting the Internet Explorer helps. There is no javascript error or any other exception.

I have made tests with similar websites without ajax without any problem., so I think this may have to do with ASP.NET AJAX. The problem occurrs with Internet Explorer 6 and 7.

This is the code of the popup website:

<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div id="header">
<h1>
<asp:Label runat="server" Text="folder choice" ID="LaHeader"></asp:Label>
</h1>
</div>
<div id="haupt">
<div id="navi">
<asp:UpdatePanel runat="server" ID="UpPaTreeView" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:TreeView runat="server" ID="TrViStructure" DataSourceID="XmDaSoStructure" OnSelectedNodeChanged="TrViStructure_SelectedNodeChanged">
<DataBindings>
<asp:TreeNodeBinding DataMember="Root" PopulateOnDemand="True" TextField="Name" ValueField="GUID" />
<asp:TreeNodeBinding DataMember="Folder" TextField="Name" ValueField="GUID" />
<asp:TreeNodeBinding DataMember="Underfolder" TextField="Name" ValueField="GUID" />
</DataBindings>
<NodeStyle CssClass="TreeItem" />
<HoverNodeStyle CssClass="TreeItemHovered" />
<SelectedNodeStyle CssClass="TreeItemSelected" />
</asp:TreeView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div id="content">
<asp:UpdatePanel ID="UpPaStatus" runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Panel ID="PaButton" runat="server" Visible="false">
<div id="controls">
<asp:Button OnClientClick="closewindow()" runat="server" CssClass="button" Text="Close"
ID="BuClose" />
</div>
</asp:Panel>
<asp:Panel ID="PaMessage" runat="server" Visible="false">
<div id="label">
<asp:Label ID="laErrorHeader" runat="server" Text="Header"></asp:Label><br />
<asp:Label ID="laErrorMessage" runat="server" Text="Label"></asp:Label>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpPaTreeView">
<ProgressTemplate>
<div id="update">
<img src="img/ajax-loader-blueBg.gif" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</div>
<asp:XmlDataSource runat="server" ID="XmDaSoStructure" DataFile="~/XML/Folders.xml">
</asp:XmlDataSource>
</form>

<script type="text/javascript">
function closewindow()
{
window.opener = this;
window.close();
}

</script>

</body>


Hi c.kr

It is not recommended to add the line number in your source code. Would you please modify it and provide more C# code and XML file related to your page ?


Hi, sorry for the line numbers, I removed it.

This is the used xml file for the treeview:

<Folder Name="foobar" GUID="some guid">
<Folder Name="foobar2" GUID="some guid2"></Folder>
<Folder Name="foo" GUID="5871D39C-7DD0-DB11-A445-0003FF6D5330">
<Folder Name="bar" GUID="E8C495C8-7DD0-DB11-A445-0003FF6D5330">
</Folder>
</Folder>
</Folder>
 This is the code behind file for the webpage:
public partialclass FolderChoice : System.Web.UI.Page
{
string _objectId =string.Empty;
CrmService _service;

private SessionData sessionData
{
get {return Session["SessionData"] ==null ?null : (SessionData)Session["SessionData"];
}
set { Session["SessionData"] =value;
}
}

protected void Page_Load(object sender, EventArgs e)
{
sessionData = CRMplusServiceConnector.GetSessionData(Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"]);
_objectId = Server.UrlDecode(Request.QueryString["oId"].ToString());

LaHeader.Text = sessionData.Translation["folderchoice.LaHeader"];
BuClose.Text = sessionData.Translation["folderchoice.BuClose"];
}

private void ConnectToCrm()
{
_service =new CrmService();

_service.Url = CRMplusServiceConnector.Configuration["crmServiceUrl"];
_service.Credentials = System.Net.CredentialCache.DefaultCredentials;

//----------------------
// Gets the Current User's Information
//---------------------- WhoAmIRequest userRequest =new WhoAmIRequest();
WhoAmIResponse userResp = (WhoAmIResponse)_service.Execute(userRequest);

//----------------------
// Set UserId of current User as CallerId
//---------------------- _service.CallerIdValue =new CallerId();
_service.CallerIdValue.CallerGuid = userResp.UserId;

//----------------------
// Cache credentials so we don't have to re-authenticate on each request.
//---------------------- _service.PreAuthenticate =true;
}

protected void TrViStructure_SelectedNodeChanged(object sender, EventArgs e)
{
this.PaMessage.Visible =false;

PaButton.Visible =false;
TrViStructure.Enabled =false;
TrViStructure.EnableClientScript =false;

SelectFolder();

TrViStructure.Enabled =true;
TrViStructure.EnableClientScript =true;
PaButton.Visible =true;
}

private void SelectFolder()
{
try { ConnectToCrm();// Create the target object for the request TargetRetrieve<someEntitiy> targetDoc =new TargetRetrieve<someEntity>();

// Set the target object's IDstring guiddoc = _objectId.Replace('{',' ');
guiddoc = guiddoc.Replace('}',' ');
guiddoc = guiddoc.Trim();
targetDoc.EntityId =new Guid(guiddoc);

// Create the request object RetrieveRequest reqDoc =new RetrieveRequest();

// Set the request object's properties reqDoc.Target = targetDoc; reqDoc.ColumnSet =new AllColumns();

// Execute the request RetrieveResponse retDoc = (RetrieveResponse)_service.Execute(reqDoc); <someEntity> curDoc =new <someEntity>();
if ( retDoc.BusinessEntity !=null )
{
curDoc = (<someEntity>)retDoc.BusinessEntity;
}
else { Environment.Exit(1); } curDoc.new_documentfolderid =new Lookup();
curDoc.new_documentfolderid.type = EntityName.new_folder.ToString();
curDoc.new_documentfolderid.Value =new Guid(TrViStructure.SelectedNode.Value.ToString());
_service.Update(curDoc);
}
catch ( System.Web.Services.Protocols.SoapException exc )
{
ShowException(exc);
}
}

private void ShowException(System.Web.Services.Protocols.SoapException exc)
{
this.PaMessage.Visible =true;
this.laErrorHeader.Text = sessionData.Translation["folderchoice.LaError"];
this.laErrorMessage.Text = exc.Detail.InnerText;
}
}

I replaced one of our classes with <someEntity>. The service which is called belongs to Microsoft Dynamics CRM.

Hi c.kr,

Sorry for the delay.I'm failed to reproduce your problem after wholly copied your code into a new project. The best way to indicate the exact root cause is dubugging it step by step in VS2005. By the way, Treeview control is not support very well inside UpdatePanel.http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx please focus on "Controls that Are Not Compatible with UpdatePanel Controls ".

If you has found it , please share it with us.

No comments:

Post a Comment