Tip: ASP.Net/AJAX – Javascript in Label/Textbox Text
Developed by Jon
Hi All,
I though I would share a problem that I had (and resolved) using ASP.Net AJAX. The problem occurs if you want to output some Javascript to a Textbox (for example: for a user to copy and paste into their own page), which is nested in an UpdatePanel. AJAX returns an HTTP 500 error.
The reason seems to be that the Javascript in the textbox interferes with the javascript generated by MS AJAX to handle the partial page updates of the UpdatePanel.
So if like me you need to output some Javascript to the page for a user to cut and paste, a work around is to use a literal control and the HTMLEncode function of the Server object as follows:
- Literal1.Text = Server.HTMLEncode(“<Script src=’example.js’ type=’text/javascript’></script>“)
I hope that helps anyone that has been puzzled by this error.
There are no comments yet.
Leave a comment