How to disable HTML tag validation on a specific TextBox?

主宰稳场 提交于 2019-12-13 02:05:39

问题


I have a form where one of the fields would allow entry of HTML tags.

<asp:TextBox ID="someID" runat="server" TextMode="MultiLine" />

In this field I have a RequiredFieldValidator validation only. Unfortunately, after any PostBack if the content of any of the fields includes HTML tags or any other potentially dangerous code - the entire ViewState is cleaned.

Setting ValidateRequest to false does not help.

I'm using IIS 7.5 and .NET 4.0.

Any ideas?


回答1:


You also need to set the

 <system.web>
       <httpRuntime requestValidationMode="2.0"/>
 </system.web>

in addition to : <%@ Page ValidateRequest="false"> on top of the page.

If you want to disable request validation for whole application, set :

<system.web>
      <pages validateRequest="false" />
</system.web>



回答2:


I would add a jqueryvalidator instead, and then validate on post as well.. It gives you more control and can give you some "smoother" effects.

For example: http://docs.jquery.com/Plugins/Validation/Validator



来源:https://stackoverflow.com/questions/3656523/how-to-disable-html-tag-validation-on-a-specific-textbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!