我们用textbox提交内容的时候,页面在显示textbox的内容时,HTML格式会对页面显示产生一定的负面效果。所以我们要过滤掉HTML格式。以下是过滤HTML格式的代码块。
1先引入命名空间
2Imports System.Text.RegularExpressions
3代码块:
4 Public Shared Function HTMLEncode(ByVal reString As String) '转换HTML代码
5 Dim Str As String = reString
6 If Str.Length > 0 Then
7 Str = Replace(Str, ">", ">")
8 Str = Replace(Str, "<", "<")
9 Str = Replace(Str, Chr(9), " ")
10 Str = Replace(Str, Chr(39), "'")
11 Str = Replace(Str, Chr(34), """)
12 Str = Replace(Str, Chr(13), "")
13 Str = Replace(Str, Chr(10), "<br/>")
14 HTMLEncode = Str
15 End If
16 End Function
2Imports System.Text.RegularExpressions
3代码块:
4 Public Shared Function HTMLEncode(ByVal reString As String) '转换HTML代码
5 Dim Str As String = reString
6 If Str.Length > 0 Then
7 Str = Replace(Str, ">", ">")
8 Str = Replace(Str, "<", "<")
9 Str = Replace(Str, Chr(9), " ")
10 Str = Replace(Str, Chr(39), "'")
11 Str = Replace(Str, Chr(34), """)
12 Str = Replace(Str, Chr(13), "")
13 Str = Replace(Str, Chr(10), "<br/>")
14 HTMLEncode = Str
15 End If
16 End Function
1<%@ Page Language="vb" validateRequest="false" AutoEventWireup="false" Codebehind="Test.aspx.vb" Inherits="_03_et.Test"%>
2要在HTML页中加入validateRequest="false"
3
2要在HTML页中加入validateRequest="false"
3
最近调用
Label1.Text = Parm.HTMLEncode(TextBox1.Text)