Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 7th, 2007, 12:40 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default AJAX w/ ASP.NET Crashes IE??

I am completely befuddled by this and can not seem to come with a reason why or how to resolve it.

My situation is pretty simple:

I have a page that contains 4 panels that change visibilty based upon user interaction. (For example clicking button A would reval panel A and hide all others.)

Now everything works fine with this portion of the UI but a request came down to add functionality that would return a list of data based upon user input without causing the screen to refresh, so I implemented a simply Ajax routine that returned the necessary data to the UI and it works great.

My problem is this: if I simply click the buttons that control the all the different panels everything works as it should. If I go down and type into the text box that is wired to the Ajax event it works as it is intended BUT after I have executed my Ajax routines if I click on a button that attempts to unhide a panel (hence causing the server to post back) IE throws an error saying that it has encountered a problem and needs to close.

Here are the pertinent Ajax routines:
Code:
               var req = false;
                function Initialize(){
                    req = false;
                    if(window.XMLHttpRequest){//Mozilla, Safari, etc
                        req = new XMLHttpRequest();
                        if(req.overrideMimeType){
                            req.overrideMimeType('text/html');
                        }
                    }
                    else if(window.ActiveXObject){//IE
                        try{
                            req = new ActiveXObject("Msxml2.XMLHTTP");
                        }
                        catch(e){
                            alert('An error has occured with IE XML Request');
                        }
                    }

                    if(!req){
                        alert('Cannot create XMLHTTP instance!');
                        return false;
                    }

                }
                function SendQuery(key, panel)
                {    
                    Initialize();        
                    var url='/MetroParks/VolunteerAjax.aspx?k='+key+ '&panel=' + panel ;

                    if(req!=null)
                    {
                        req.onreadystatechange = Process;
                        req.open("GET", url, true);
                        req.send(null);
                    }
                }
                function Process()
                {
                    if (req.readyState == 4)
                    {
                        if (req.status == 200)
                        {
                            if(req.responseText==""){
                                HideDiv("autocomplete");
                                }
                            else
                            {
                                ShowDiv("autocomplete");
                                var parentElement = document.getElementById('autocomplete');
                                try
                                {
                                    parentElement.innerHTML='';
                                    parentElement.innerHTML=req.responseText;
                                }
                                catch(e){
                                    var wrappingDiv = document.createElement('div');
                                    wrappingDiv.innerHTML = '';
                                    wrappingDiv.innerHTML = req.responseText;
                                    parentElement.appendChild(wrappingDiv);
                                    }
                                //document.getElementById('autocomplete').innerHTML = req.responseText;
                            }
                        }
                        else
                        {
                            document.getElementById("autocomplete").innerHTML=
                                "There was a problem retrieving data:<br>"+req.statusText;
                        }
                    }
                }
I am assuming that this has something to do with the XMLHttp object but, problem is, I can't seem to find any information on Google about this problem.

Any help here would be greatly appreciated.

Thanks!

-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old December 7th, 2007, 01:33 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What version of IE?
Is there a javascript error that happens before IE shuts down?
Have you tried this on another browser?

-Peter
 
Old December 7th, 2007, 02:38 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hi Peter.

1. IE6+
2. No the code is clean, there are no JS errors.
3. Yes. And ultimately that led to the resolution.

After I posted this thread I investigated the page in Firefox and, instead of Firefox crashing, it gave me a compiler error from the runtime: "The state of the current page is invalid...".

These lines of code are ultimately what caused the problem:

Code:
...
catch(e)
{
    var wrappingDiv = document.createElement('div');
    wrappingDiv.innerHTML = '';
    wrappingDiv.innerHTML = req.responseText;
    parentElement.appendChild(wrappingDiv);
}
This makes sense coupled with the error message: I am adding data to the page that I am not accounting for in ViewState.

I have since removed the try{}catch{} with:
Code:
document.getElementById("autocomplete").innerHTML= req.responseText;
Originally the reason for the try{} catch{} was because the code would crash when I tried to preform the above operation however, as I found out, this was how I was sending data back to the browser. I have since adjusted that and the above logic works fine.

Thanks none the less Peter.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET 2.0 Ajax raminriahi General .NET 2 September 5th, 2007 12:48 PM
Turning a regular ASP.NET App into an AJAX ASP.Net donrafeal7 Ajax 2 August 31st, 2007 12:33 AM
ajax in asp.net imjayakumar Crystal Reports 0 April 3rd, 2007 07:26 AM
ASP.NET AJAX inkrajesh ASP.NET 2.0 Professional 3 January 19th, 2007 03:42 PM
using AJAX in ASP.Net muskaanbajaj ASP.NET 1.0 and 1.1 Professional 3 February 24th, 2006 05:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.