views:

62

answers:

2

I have a series of controls on an ASP page. Some are inside an UpdatePanel and some are not.

If I put an XML tag in one of the text boxes (eg, "<foo>") then all the controls within the UpdatePanel don't work. As soon as the tags are removed, everything is fine.

My 'submit' button is in the UpdatePanel and the breakpoint on btnSubmit_Click is only hit when there aren't tags in the text boxes.

I'm a long-time C# dev but quite new to ASP.NET so might be missing something obvious... this just isn't the behaviour I expect.

A: 

You can't put markup in a textarea. You must HTML-escape any markup characters inside textarea just as you must with any other element.

<textarea>&lt;foo> &amp; &lt;bar></textarea>

Although in practice browsers will usually work out what you mean and show any < characters as-is, it's still invalid HTML and non-well-formed XML (presumably this is also the root of your issue in ASP.NET, though without specific code it's difficult to tell).

bobince
I think he means that he is typing the tag into the textbox when the page is running, which then causes the page to stop working until the tag is removed.
Jason Berkan
Hi bobince, thanks for the reply. Jason is correct, it was at run-time that the issue was arising (which I didn't really make clear). Apologies but thanks again.
Rich Stokoe
+1  A: 

If you were to take the UpdatePanel off the page, you'd find that the postback was causing an error because .NET thinks that "<foo>" is a potentially dangerous bit of data to accept at the server. See this question on StackOverflow. You don't see the error because the error page HTML is being returned to the UpdatePanel's ajax call rather than direct to you browser, and the UpdatePanel doesn't know what to do with it.

You can turn off the checking by adding

ValidateRequest="false"

to the <@Page ... > directive at the top of your aspx file. Or you can modify the web.config to get the same effect right across your web app.

d4nt
That sorted it. Many thanks!
Rich Stokoe