asp文本框中的特殊字符问题 [英] Special charecter problem in asp textbox

查看:145
本文介绍了asp文本框中的特殊字符问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在asp文本框中使用特殊字符。但当我用其他控件如按钮进行任何操作时,则在客户端级别

Sys.WebForms.WebequestManager问题引发。



我该怎么做才能在asp文本框中允许特殊字符?



i已尝试使用Page指令验证ValidateRequest =false属性但是
还有
问题。

解决方案

你使用的是ASP.NET,而不是ASP。没有asp或asp.net文本框这样的东西。它只是一个HTML输入控件。我想你说你使用看起来像脚本注入的字符会遇到问题。



http://msdn.microsoft。 com / en-us / library / ff647397.aspx [ ^ ]解释了如何启用验证。反转建议将其关闭。如果您已经尝试了所有这些,请尝试发布您已完成的代码和实际的错误消息。


一个简洁的解决方案,而不将请求验证转为关闭是使用JavaScript的。假设您的文本框是TextBox1并且在按钮(Button1)上单击要执行服务器端操作的事件,请按照以下步骤操作:

1)将此脚本包含在文档的头部:

< script> 
function ReplaceCharacter(){
var value =( document .getElementById(' TextBox1')。value);
value = value.replace(' <'' < ;;'); // <之间没有空格和;
value = value.replace(' >',< span class =code-string>' >;'); // >之间没有空格和;
document .getElementById(' TextBox1')。value = value;
}
< / script>



2)代码背后写:

 Button1.Attributes.Add(  onclick   ReplaceCharacter();); 



3)无论你想获得什么值服务器端代码中的文本框写入:

  string  myString = Server.HtmlDecode(TextBox1.Text); 


hi,
I am using special character in asp textbox. but when i do any operation with another control like buttons, then at client level
Sys.WebForms.WebequestManager problem raise.

what i should i do to allow special character in asp textbox?

i already tried ValidateRequest="false" attribute with Page directive but
problem still there.

解决方案

You''re using ASP.NET, not ASP. There is no such thing as an asp or asp.net textbox. It''s just a HTML input control. I think you''re saying you get an issue with using characters that look like a script injection.

http://msdn.microsoft.com/en-us/library/ff647397.aspx[^] explains how to turn on validation. Reverse the advice to turn it off. If you''ve tried all that, try posting code of what you''ve done, and the actual error message.


A neat solution without turning requestvalidation to "off" is to use javascript. Suppose your textbox is "TextBox1" and on button("Button1") click event you want to perform server side operation follow the steps:
1) Include this script in head of your document:

<script>
  function ReplaceCharacter() {
   var value = (document.getElementById('TextBox1').value);
   value = value.replace('<', '< ;');//no space between < and ;
   value = value.replace('>', '> ;');//no space between > and ;
   document.getElementById('TextBox1').value = value;
  }
 </script>


2) In code behind write:

Button1.Attributes.Add("onclick","ReplaceCharacter();");


3) Wherever you want to get the value of textbox in server side code write:

string myString = Server.HtmlDecode(TextBox1.Text);


这篇关于asp文本框中的特殊字符问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆