Server HtmlEncode : HTML Encode « Development « ASP.Net






Server HtmlEncode

<%@ Page Language="VB" %>
<script runat="server">
    Sub Button1_Click(sender As Object, e As EventArgs)
      Dim fullString, subString As String
      Dim startPos, length As Integer
    
      startPos = CInt(TextBox2.Text)
      length = CInt(TextBox3.Text)
    
      fullString = TextBox1.Text
      subString = fullString.SubString(startPos, length)
      Label1.Text = subString
    End Sub
    
    Sub Button2_Click(sender As Object, e As EventArgs)
      Dim myString As String
      Dim myWords As String()
      myString = TextBox1.Text
      myWords = myString.Split(" ".toCharArray())
    
      Label1.Text = "<ul>"
    
      Dim word As String
      For Each word in myWords
        Label1.Text = Label1.Text & "<li>" & word & "</li>"
      Next word
    
      Label1.Text = Label1.Text & "</ul>"
    End Sub
    
    Sub Button3_Click(sender As Object, e As EventArgs)
      Label1.Text = Server.HtmlEncode(TextBox1.Text).Replace(vbCrLf, "<br/>")
    End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
            <asp:TextBox id="TextBox1" runat="server" Height="112px" Width="259px" TextMode="MultiLine"></asp:TextBox>
        </p>
        <p>
            start: 
            <asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
        </p>
        <p>
            length: 
            <asp:TextBox id="TextBox3" runat="server"></asp:TextBox>
        </p>
        <p>
            <asp:Label id="Label1" runat="server"></asp:Label>
        </p>
        <p>
            <asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Show Substring"></asp:Button>
            &nbsp;<asp:Button id="Button2" onclick="Button2_Click" runat="server" Text="Split"></asp:Button>
            <asp:Button id="Button3" onclick="Button3_Click" runat="server" Text="Copy"></asp:Button>
        </p>
    </form>
</body>
</html>

           
       








Related examples in the same category