Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hye..
My question is really simple. i am about to make a forum in my system. just like this code project forum. the question is how to make a preview section after user has entered text in the textbox? just like the preview section below.

I have been trying this code but the label doesn't come out:
XML
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="testupdatet.aspx.vb" Inherits="testupdatet" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <br />
        <br />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
             <fieldset>
                <asp:TextBox ID="TextBox1" runat="server" Height="34px" Width="249px"></asp:TextBox>
                <br />
                <br />
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                <br />
                <br />
                <asp:Label ID="Label1" runat="server"></asp:Label>
                <br />
                <br />
                <asp:Label ID="Label2" runat="server"></asp:Label>
                  </fieldset>
            </ContentTemplate>
        </asp:UpdatePanel>
        <br />
        <br />
    
    </div>
    </form>
</body>
</html>

this is my vb code:

VB
Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
       Label1.Text = TextBox1.Text

   End Sub

   Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
       Label2.Text = TextBox2.Text
   End Sub
Posted
Updated 22-Apr-11 9:09am
v2

1 solution

You will have to set the textbox's AutoPostBack="true" and also set the OnTextChanged of the textbox. The textbox's text changed event will fire only when you tab out of the control, it will not fire for each key press.

ASP
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
            <ContentTemplate>
             <fieldset>
                <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
                <br />
                <br />
                <asp:TextBox ID="TextBox2" runat="server" AutoPostBack="true" OnTextChanged="TextBox2_TextChanged"></asp:TextBox>
                <br />
                <br />
                <asp:Label ID="Label1" runat="server"></asp:Label>
                <br />
                <br />
                <asp:Label ID="Label2" runat="server"></asp:Label>
                  </fieldset>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>
 
Share this answer
 
Comments
snamyna 23-Apr-11 1:58am    
thanks. that works. :)
anyway, from what i have tested, it does not come out just like the code project forum.when i entered the text into the textbox, it waits until particular second, then it will refresh the the whole text in textbox to assign to label. but all i want it to be is like this code project. it refresh every single alphabet that i entered.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900