Rediscovering the Obvious

…stumbling in the footsteps of greatness

Difference between setting InnerText and InnerHtml

without comments

What’s the difference between these two lines?

scriptInit.InnerHtml = string.Format(creationFormat, outerDiv.ClientID, someOtherString);

scriptInit.InnerText = string.Format(creationFormat, outerDiv.ClientID, someOtherString);

Answer: The first one doesn’t do special character escaping, the second one does.

With a format string that looks like “createSilverlight(‘{0}’, ‘/{1}.xaml?x=233&y=300&m=1\’ );” it got a bit ugly with the &’s coming out as &, especially when it came back around to the server with the query string mangled.
 

 

Written by erwilleke

February 22nd, 2008 at 6:56 pm

Posted in Uncategorized

Leave a Reply