Introduction: Server.HTMLEncode and Server.URLEncode are commonly used in ASP functions, in the asp.net also have similar functions: HTMLEncode and UrlEncode (note case) below with an example to introduce.
Server.HTMLEncode and Server.URLEncode are very common functions used
by ASP developers. So, as may have guessed two functions
have asp.net counterparts. HtmlEncode and UrlEncode (notice case) are
Part of the System.Web.HttpUtility namespace.
This is the demo
urlencode.asp?test=1&test1=2
Urlencode.asp%3ftest%3d1%26test1%3d2
This is a test & hopefully it works!
**********************************
This is the code:
**********************************
<%@ Page language= "VB"%>
<%@ Import namespace= "System.Web.HttpUtility"%>
<title>htmlencode and UrlEncode the asp.net way</title>
<script language= "VB" runat= "Server" >
Sub Page_Load (sender as Object, E as EventArgs)
' Assign we test URL to a variable, Assign the variable to our
Label control
Dim Strurltext as String = "urlencode.asp?test=1&test1=2"
Strurl.text = Strurltext
' Encode the ' test URL, assign it to a variable, assign the
Variable to We label control
Dim Strurlencodetext as String = UrlEncode (Strurltext)
Strurlencode.text = Strurlencodetext
' Assign we test URL to a variable, Assign the variable to our
Label control
Dim strHTMLText as String = "Works!Strhtml.text = strHTMLText
' Encode the ' test HTML, assign it to a variable, assign the
Variable to We label control
Dim Strhtmlencodetext as String = HtmlEncode (strHTMLText)
Strhtmlencode.text = Strhtmlencodetext
End Sub
</script>
<body>
<asp:label id= "strURL" forecolor= "Red" font-bold= "true" runat=server/>
<p>
<asp:label id= "Strurlencode" forecolor= "Blue" font-bold= "true" runat=server/>
<p>
<asp:label id= "strhtml" forecolor= "Red" font-bold= "true" runat=server/>
<p>
<asp:label id= "Strhtmlencode" forecolor= "Blue" font-bold= "true" runat=server/>
</body>