More on ASP.NET Callbacks

Published 17 June 05 03:49 PM | despos

I'm still having troubles with the ASP.NET client callback mechanism with non-IE browsers. However, it seems that all of my troubles originate from imperfect, because likely not standard, DOM calls. I can now have the Web server respond to the calls of a FireFox client page. But I'm still looking for a plausible explanation of the following "miracle". I do have sample pages that, when run in FireFox, update the UI through innerHTML. (It seems that FireFox doesn't accept innerText.) If I do the same in a Javascript callback invoked within a callback, setting innerHTML doesn't work. Nicely enough, one of the official samples you get from MS, just uses innerHTML to refresh the page--and it works for me too through FireFox.

Mysteries of a late spring night 

Comments

# Jim said on June 17, 2005 10:17 AM:

Its my opinion that if you are rewriting an element on a page your better off writing its outerHTML. In this manner you can render a control to a string serverside and simply pass the resulting html through Javascript during the call back.

Firefox has no support for that property however, so you'll have to write roll your own.

I have been using this function for a few years with success.

function replaceOuterHTML(elm,outerHTML)
{
if(elm)
{
if(elm.outerHTML)
{
//ie5+
elm.outerHTML = outerHTML;
return;
}
else if(elm.innerHTML != undefined)
{
//what is the tag we are trying to replace?
var innerHTML = '';
var endtagname = outerHTML.indexOf(' ');
var tag = outerHTML.substr(1,(endtagname-1));
var newNode = document.createElement(tag);
var firstCloseTag = outerHTML.indexOf('>');
//put the new tag out there
elm.parentNode.replaceChild(newNode,elm);
//set the attributes
var strParse = outerHTML.substr(endtagname+1,firstCloseTag-(endtagname+1));
//alert('parsing:' + strParse + '.');
while(strParse.length > 0)
{
if(strParse.substr(0,1) == ' ')
{
strParse = strParse.substr(1,strParse.length);
}
else
{
var start = strParse.indexOf('="');
var attributeName = strParse.substr(0,start);
var end = (strParse.indexOf('"',(start + 2))) - (start + 2);
var attributeValue = strParse.substr(start + 2, end);
newNode.setAttribute(attributeName,attributeValue);
strParse = strParse.substr(start + end + 4, strParse.length);
}
}
//set the innerHTML
if(outerHTML.substr(firstCloseTag-1,1) == '/')
{
innerHTML = outerHTML.substr(firstCloseTag +1, outerHTML.length);
}
else
{
var i = outerHTML.length - 2;
var strStartClose = '';
while(strStartClose != "<" && i>0)
{
strStartClose = outerHTML.substr(i,1);
i--;
}
innerHTML = outerHTML.substr(firstCloseTag +1,i - firstCloseTag);
}
//alert('innerHTML=' + innerHTML + '.');
newNode.innerHTML = innerHTML;
return;
}
}
}

# Scott said on June 17, 2005 12:54 PM:

Right, Firefox doesn't have an innerText property. It's pretty easy to add one though.

http://www.lazycoder.com/weblog/archives/2005/02/08/adding-innertext-to-mozilla-and-other-browsers/

# rq said on June 17, 2005 06:15 PM:

I had to solve a similar problem using outerHTML for an ajax asp.net sample , http://rquintino.europe.webmatrixhosting.net/sample.aspx . I used the solution described at http://webfx.eae.net/dhtml/ieemu/htmlmodel.html . Worked great.

Leave a Comment

(required) 
(required) 
(optional)
(required)