ASPAlliance.com : The #1 Active Server Pages .NET Community The #1 ASP.NET Community
Search   Search

Subscribe   Subscribe

Powered by ORCSWeb Hosting


Site Stats


Powered By ASP.NET
 
Featured Sponsor

Featured Columnist


Featured Book
ASP.NET Tips, Tutorials, and Code
ASP.NET Tips, Tutorials, and Code

Find Prices
Read Review
Read Review
Sample Chapter
Sample Chapter


New! asp.netPRO

We publish our articles in the standard RSS format.

Powerful .NET Email Component

Code Sharing Software
Click here to return to my article index

Code:

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.HttpUtility" %>
<html>
<head>
<title>HTMLEncode and URLEncode the ASP.NET Way</title>

<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs) 

    'Assign our 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 our label control
    Dim strURLEncodeText As String = UrlEncode(strURLText)
    strURLEncode.Text = strURLEncodeText
    
    'Assign our test url to a variable, assign the variable to our label control
    Dim strHTMLText As String = "<h1>This is a test & hopefully it works!</h1>"
    strHTML.Text = strHTMLText

    'Encode the test html, assign it to a variable, assign the variable to our label control
    Dim strHTMLEncodeText As String = HtmlEncode(strHTMLText)
    strHTMLEncode.Text = strHTMLEncodeText

End Sub
</script>
</head>
<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/>
<br>
</body>
</html>

Result:
urlencode.asp?test=1&test1=2

urlencode.asp%3ftest%3d1%26test1%3d2

This is a test & hopefully it works!

<h1>This is a test & hopefully it works!</h1>

 Copyright © 2000-2003 ASPAlliance.com  Page Rendered at 8/28/2008 3:01:16 AM