Nathan, in addition to Cor's suggestions, let me add that there is not much
you can do at this point that can change what is output by the
htmltextwriter. It's this writer which actually minimally HTML-encodes
everything. This is possibly for xhtml comformance, since an & is not a
legal character within an xml document and needs to be escaped. So are
characters like <>. I cant imagine you working around this, without doing
something a bit trival like through the HttpResponse.Filter which gives you
a chance to rewrite what is output by the htmltextwriter before it is
transmitted to the page =P
http://msdn2.microsoft.com/en-us/library/system.web.httpresponse.filter.aspx
There is full working example in the above url, that shows you howto attach
a filter to the response stream that makes the text displayed to the page
all uppercase.You will be searching for & or whatever other html code
characters you dont want, and replacing them with the original you had
wanted.
That said, can you explain further why you want to work around this ? I dont
understand why your script shouldnt work *sometimes* with those characters
escaped.
Your problem, in my humble opinion is somewhere else, possibly in the js
code that you are writing, but i cant say much since the code you pasted
works very well *always* for me. I have pasted the code i tested below. Let
us know, what you are doing differently and under what circumstance its not
working for you.
Regards,
Alessandro Zifiglio
http://www.AsyncUI.net
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add("onchange", "if (parseInt(this.value) >= 0
&& parseInt(this.value) <= 255){ alert('more than 0 and less than a
100');}");
}
</script>
<html xmlns="
http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" Text="" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>