How to disable HTML tag validation on a specific T

2019-09-18 11:12发布

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?

2条回答
啃猪蹄的小仙女
2楼-- · 2019-09-18 11:28

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

查看更多
贼婆χ
3楼-- · 2019-09-18 11:51

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>
查看更多
登录 后发表回答