我今天弄个留言板遇到了以下的问题我做那个html过滤的功能,编了一个函数来处理,我一点提交的时候出现了这么一句异常信息:“从客户端(tbContent="<h1></h1>")中检测到有潜在危险的 Request.Form 值”所以我感觉应该在前台处理,所以我又打算弄个javaScript来处理,可是我不知道在那个按钮的什么地方能让他调用这个javaScript..............有点乱。。过程大约是这样:
一点提交按钮,调用javascript的一个函数
函数处理留言的内容
然后把处理好的字符串赋值给 textBox
然后提交给服务器处理
谁能给稍微写个demo,再给讲讲要是有更好的解决以上问题的方案可以给传授一下
谢谢大家

解决方案 »

  1.   

    <%@ Page language="c#" Codebehind="WebForm4.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm4" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm4</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    <script language=vbscript>
    function strleach(str)'过滤非法字符函数 
    dim tempstr 
    if str="" then exit function 
    tempstr=replace(str,chr(34),"")' " 
    tempstr=replace(tempstr,chr(39),"")' ' 
    tempstr=replace(tempstr,chr(60),"")' < 
    tempstr=replace(tempstr,chr(62),"")' > 
    tempstr=replace(tempstr,chr(37),"")' % 
    tempstr=replace(tempstr,chr(38),"")' & 
    tempstr=replace(tempstr,chr(40),"")' ( 
    tempstr=replace(tempstr,chr(41),"")' ) 
    tempstr=replace(tempstr,chr(59),"")' ; 
    tempstr=replace(tempstr,chr(43),"")' + 
    tempstr=replace(tempstr,chr(45),"")' - 
    tempstr=replace(tempstr,chr(91),"")' [ 
    tempstr=replace(tempstr,chr(93),"")' ] 
    tempstr=replace(tempstr,chr(123),"")' { 
    tempstr=replace(tempstr,chr(125),"")' } 
    strleach=tempstr 
    end function 
    </script>
    </HEAD>
    <body>
    <form id="Form1" method="post" runat="server">
    <asp:TextBox id="TextBox1" runat="server" TextMode="MultiLine" Width="304px" Height="144px"></asp:TextBox>
    <INPUT type="button" value="Button" onclick="document.getElementById('TextBox1').innerText=strleach(document.getElementById('TextBox1').innerText)">
    </form>
    </body>
    </HTML>