Simple Textbox Textchange event example


In this article I'm going to explain Text change even of text box control using asp.net. Just drag and drop one text box and label control from toolbox and then change this control name into txtName and lblResult.

In this article I'm going to explain Text change even of text box control using asp.net. Just drag and drop one text box and label control from toolbox and then change this control name into txtName and lblResult. Right Click the Text box control and then go to property window (F4) then double click text changed event or else just double click text box control.

Immediately Tex changed event code will display like this


protected void txtName_TextChanged(object sender, EventArgs e)
{


}


Then write text like this


lblResult.Text = "Welcome to dotnetspider Mr. " + txtName.Text.ToString();


The full code as follows


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{

protected void txtName_TextChanged(object sender, EventArgs e)
{
lblResult.Text = "Hello " + txtName.Text.ToString();

}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{

}
}





<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>
Enter Your Name <asp:TextBox ID="txtName" AutoPostBack ="true" runat="server" OnTextChanged="txtName_TextChanged"></asp:TextBox>
<asp:Label ID="lblResult" runat="server" Text="Label"></asp:Label></div>
</form>
</body>
</html>




Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: