Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Thursday, September 25, 2008

JavaScript HTMLEncode function

Found this neat trick on another blog (http://lunarmedia.com/blogs/lunarmedia_blog/archive/2006/10/23/120405.aspx) to escape characters for presentation in HTML:

function escapeHTML (str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
}; 

Monday, March 3, 2008

How to resolve "__doPostBack is not defined" error

Thanks to Julien Pinquié:

When I ran across this, I found that I'd closed a <script> tag referring to an external .js file with /> notation instead of <script></script>; the <script> tag doesn't accept this notation for whatever reason.

Thursday, January 31, 2008

JavaScript button disable with postback

When an ASP.NET server-side button is given client-side JavaScript code to execute when handling onclick, the button no longer posts back by default. However, there is a small piece of code you can add to the onclick attribute of the button to re-enable the postback behavior.

Adding this code in the Page_Load method will remove a server-side button's postback call:

btnConfirm.Attributes.Add("onclick", "Confirm_Click();")

But writing the code like this will reinstate the postback call:

btnConfirm.Attributes.Add("onclick", "Confirm_Click(); " + ClientScript.GetPostBackEventReference(btnConfirm, ""))