Omnimaga

General Discussion => Technology and Development => Web Programming and Design => Topic started by: BlakPilar on January 07, 2012, 03:24:33 pm

Title: ASP.NET Textbox help
Post by: BlakPilar on January 07, 2012, 03:24:33 pm
So I've been fooling around with ASP.NET and I have what would seem to work, but it doesn't... I was just wondering if anyone who knew ASP.NET could help.

Spoiler For Site.master:
<body>
    <form runat="server">
        <div class="main">
            <asp:ContentPlaceHolder ID="MainContent" runat="server"/>

            <asp:TextBox runat="server" ID="txt" />
            <asp:Label runat="server" ID="lbl" />

        </div>
        <div class="clear">
        </div>
    <div class="footer">
       
    </div>
    </form>
</body>

Spoiler For Site.master.cs:
public partial class SiteMaster : System.Web.UI.MasterPage {

    protected void Page_Load(object sender, EventArgs e) {
        txt.AutoPostBack = true;
        txt.TextChanged += new EventHandler(textChanged);
    }

    public void textChanged(object sender, EventArgs e) {
        lbl.Text = Server.HtmlEncode(txt.Text);
    }
}

EDIT: I've modified the source. It works only when the textbox loses focus, though. Also, if there are any HTML-specific characters (such as '>' and '<') there's an error thrown. I thought Server.HtmlEncode() was supposed to take care of that?