Re: reading from text area throwing exception with <p>



Hi Vikas,

ASP.NET 1.1/2.0 by default enable requestValidation so that any script or
html markup tags (like < , > ....) will raise runtime exception. For your
scenario, I think you can consider the following options according to
what's the exact behavior you want and what task will your web page
designed to do:

1.If you want to let client users input html/xml markup tags in entry
fields(textbox, ...) and just want to display them again (write out), you
can simply disable the "validateRequest" for that particular page(which
will accept html markup input) and then on server-side, use
Server.HtmlEncode or HttpUtility.HtmlEncode to encode the content in the
textbox. e.g

<%@ Page ..................... ValidateRequest="false" %>

string safeString = Server.HtmlEncode(TextBox1.Text);

Label1.Text = "<p>" + safeString + "</p">


2. Still turn on the "validateRequest", but peform valdation against the
Textbox's input content at client-side. For example, you can use a
customValidator control on the ASP.NET page to validate that certain
textbox in which the client user may input some html tags. And for the
custom Validator's client-side validation script, you can use javascript
function to check whether the input content contains those particular chars
(such as < , > .....).

3. Use the Textbox's client-side "onchange" event to perform the content
checking, in this case, the script checking will be performed everytime
after the client-user modify the content in the textbox.

Here are some articles discussing on peform content validation against
textbox entry field through javascript, you can replace those script
function with your own ones according to your validation requirement:

#Client-Side Form Verification with JavaScript
http://www.webdevelopersnotes.com/tips/html/restricting_visitor_input_from_a
_text_box_html_textarea_element.php3

http://webdeveloper.internet.com/javascript/javascript_form_verification.htm
l

#Using JavaScript to prevent or trigger form submission when ENTER is hit
http://www.cs.tut.fi/~jkorpela/forms/enter.html


#Checking/Validating Fields
http://www.irt.org/script/form.htm#5


Please feel free to let me know if there is anything unclear above or any
other information you wonder.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.




.



Relevant Pages

  • RE: Multiview and Validation
    ... also you're right about the client-side validation: ... possible to validate them at client-side. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: strange server-side validation postback
    ... "OnClientClick" property to set client-side onclick script handler. ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Here is Code (C#) for CheckBox Validation on Server and Client
    ... You don't have support on ... Its not hard to write the client-side for this. ... Creator of "Professional Validation And More" at ...
    (microsoft.public.dotnet.framework.aspnet)
  • Client-Side Validation and Double-Click Problem
    ... client-side and server-side validation for various fields on the form. ... I had to override the default client-side onsubmit event handler. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: access gridview cell from client
    ... you can use client-side script to loop through each table row and column. ... when would you do the cell value retrieving at client-side? ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet)