Category Archives: ASP.NET

OnTextChanged function in C# for ASP Text Box in ASP.NET

I tried to write a function while OnTextChanged of ASP TextBox but it didn’t work. I came up with that you have to write AutoPostBack=”true” to call the function. I want it because one of my client ask for showing preview while they changed the article before publishing or saving it. So it’s helpful while they change something in text box they can see the preview immediately. You can do this by calling a simple function.

<asp:TextBox ID="page_name_en" OnTextChanged="change_title" autopostback="true" runat="server"  />
preview here

C# Code

protected void change_title(object sender, EventArgs e)
{
//Get the text from text box
string text = ((TextBox)sender).Text;
//Preview the text and show it in Div
preview.InnerHtml = text;
}