TextChanged event of TextBox in Repeater


In a Repeater I have a TextBox with its Text property bound. How can I capture the TextChanged event of that TextBox? I couldn't find any way for that on my own by now.


7/26/2007 7:07:58 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies

Similar Articles

[PageSpeed] 56

I think in the ItemCreated event of your repeater, you would need to add an event
handler pointing to a local function that is hooked to the
TextBox.TextChanged. You can get a reference to the textbox using e.Item.FindControl

Farooq Kaiser, MCTS, MCP
Please Mark As Answer if my answer helped you.
7/26/2007 9:30:41 PM

Here is a sample:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" >
        <ItemTemplate>  <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />
                <asp:TextBox ID="priceTextBox" runat="server" Text='<%# Bind("price") %>' AutoPostBack="true" OnTextChanged="PriceTextBox_OnTextChanged"></asp:TextBox>
                <br /><br />
                <asp:TextBox ID="price2TextBox" runat="server" Text='<%# Bind("price2") %>'>
                </asp:TextBox><br />
                <asp:TextBox ID="price3TextBox" runat="server" Text='<%# Bind("price3") %>'>
                </asp:TextBox><br />


protected void PriceTextBox_OnTextChanged(object sender, EventArgs e)

        TextBox tb1 = ((TextBox)(sender));

        RepeaterItem rp1 = ((RepeaterItem)(tb1.NamingContainer));

        TextBox tb2 = (TextBox)rp1.FindControl("price2TextBox");

        TextBox tb3 = (TextBox)rp1.FindControl("price3TextBox");

        tb2.Text = Convert.ToString(Convert.ToDouble(tb1.Text) * 0.2);

        tb3.Text = Convert.ToString(Convert.ToDouble(tb1.Text) * 1.2);


7/26/2007 9:36:11 PM

Thanks for your answers,

I tried the code but the problem is, that the code in the event handler is never executed. I assume that this is due to the fact, that the Repeater creates its items after the postback data is handled.

But is there any workaround? 

7/27/2007 7:03:43 AM

Hi, meder:

The event isn't fired until the page post back, because the code is in server side.

In the client server, you can use javascript to achieve this.


<asp:TextBox runat="server" ID="id" Text='<%# Eval("name") %>' onkeypress="javascript:keyPressed()" BackColor="AliceBlue" ></asp:TextBox>

Define the function like

<script language="javascript" type="text/javascript">
function keyPressed()
    add your code here


Hope it helps.

Techie Zhang
Microsoft Online Community Support
7/30/2007 9:22:33 AM

Did you set this? AutoPostBack="true"

Post your code in question.


7/30/2007 2:13:46 PM


Thanks for your answers,

I tried the code but the problem is, that the code in the event handler is never executed. I assume that this is due to the fact, that the Repeater creates its items after the postback data is handled.

But is there any workaround? 

did a postback happened when you enter a text in the textbox ?

note that the textchanged event will be fired when the following 2 things happened ?

  1. you change the text inside the textbox
  2. the changed text box lost focus (blur)  ,eg:you press tab.

so make sure the form has been submitted after you type a text ..



Anas Ghanem.

Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

7/30/2007 2:30:25 PM

Similar Artilces:

in repeater control in textbox textchanged event i have the following error (in IE only i have this problem)
Hi, in repeater control in textbox text changed event i have the following problem in InternetExplorer only,in Mozilla it is working properly iam using EnableEventvalidation="false"  then the text changed event is not firing in IE Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation. Thanks in advancewith regards,prasanth  Post the TextBox text changed event code. See here http://www.google.com/search?hl=en&q=System.ArgumentException%3A+Invalid+postback+or+callback+argument&btnG=Google+Search&aq=f&oq= for more information on the Invalid postback or callback argument error. NC...  ...

RE: Textbox control TextChanged Event
Hi to all, I wonder f u cud help me out how to invoke a function from the code behind file after I pressed the Enter Key in a text box control.  I want to trigger this function in the textchanged event but even if i will jst pressed tab, it will do a postback to server which later i found out that it will really do a postback when u press TAB or ENTER KEY, is their any way to jst implement a postback only when i press the ENTER KEY and not with TAB also? Thanks in advance.. jerkybagz       keep the text box along with a hidden button(with help of style=display:non...

Composite control: How to bubble a textbox's TextChanged event?
I've created a composite control that contains several controls, including a textbox. I'm trying to expose the TextChanged event of the textbox as an event on the composite control. I understand that events can be bubbled up the control hierarchy and handled at a higher level, which I've attempted to do, but I can't get the bubbled event to fire. When I drop the control on an aspx I can see the TextChanged event, I can subscribe to the event, but nothing ever happens. Any suggestions? Here is what I think is the relevant code: // My eventprivate static readonly object EventT...

dynamic textBox control not firing TextChanged event when text is deleted
I have a number of textBoxes that are created dynamically.  In the process of creating them, I set the following TextBox tBox = new TextBox(); // common prop's for all TextBoxestBox.TextChanged += new System.EventHandler(this.HandlerNameHere);// set the tooltip conditionally basedstring tbID = "tb" + rowType.ToString() + "_" + cellInd;//add textBox control to cellAddTextBox(tCell, tBox, "projectEntryTextBox",tbID); //The method to add the textBox     void AddTextBox(TableCell tc, TextBox tb, string css, string tbID)    {        tb.CssClass = css;        tb.EnableViewState = false;        tb.ID = tbID;        tc.Controls.Add(tb);    } The handler (HandlerNameHere) starts out something like this ...void HandlerNameHere(object sender, System.EventArgs e)){TextBox txtBoxSender = (TextBox)sender;string strTextBoxID = txtBoxSender.ID;myClass TEH = new myClass(txtBoxSender.Text, txtBoxSender.ID);// ... do some more processing } If text is added to an empty box it fires and works as expected, great!If text is changed (e.g. a 5 => 8), works ... just fine.If existing text is deleted, the event does not fire. It returns to its previous state. e.g. text is 7 ... delete it and it returns to 7, event does not even fire.  I would think ...

Calendar Control inside Repeater, Handling Child control events in parent Data Control
Hi all,I've been researching a problem i have for a couple of days now and i'm still not sure how to even start to handle it.I'm essentially trying to build a page that will display custom form fields/controls for individual items/rows inside a repeater.I've got a fairly complex calendar i need to have working inside each individual row of the Repeater. The calendar is set up to fire the following events: OnDayRender="Calendar2_DayRender" OnSelectionChanged="Calendar2_SelectionChanged" OnVisibleMonthChanged="Calendar2_VisibleMonthChanged"My first question is how do i go about handling these calendar events in the code behind when the code behind complains that "Calendar2 does not exist in the current context"?How do i identify each unique instance of Calendar2 and handle each instances events uniquely?Any pointers to articles, pages etc is greatly appreciated. I've come across "event bubbling" but i'm not sure exactly how this works when attempting to handle a control like a calendar and not a button inside a Data Control.Thanks for any and all help! In each of those events there is a parameter to the event handler "object sender".  "sender" is the control that fired the event. You can use it by casting "sender" as your calendar object.  MyCalendarObject mycalendar = (MyCalendarObject)sender;This will give you a pointer to the control element inside the template.  What you cannot do is access a templated control directly because the IDE has no way of kn...

How to Enable/Disable the TextBox in Repeater Control on CheckChanged event of CheckBox using JavaScript.
hi all, I am using a Repeater Control in my application to display some records. Inside the Repeater, i am also displaying a CheckBox and a TextBox on each row.The textbox is initially disabled. I want to enable the TextBox on a row when the CheckBox on the same row is Checked and disable it when it CheckBox is Unchecked. I want to achieve this functionality using javascript...If anyone knows how to do this, please tell me...it's very very urgent... all posts will be greatly appreciated... thanx in advance...  Sincerely...

Repeater Control bubble event for dropdownlist control
Hi to all, I am facing a problem in repeater control that has two dropdownlist control. my problem is that i generate these two dropdownlist control using runtime datatable data as datasource for repeater control and want to enable selected index changed property for both of the drodownlist so that selecting item in one dropdownlist will cause dataitem listing in second one dropdownlist. Wating for your prompt responces. Thanks a lot Anand Sah anand@azonicinfotech.com http://www.azonicinfotech.com/     Could you post the code for repeater and dropdownlists? I don't su...

Adding Event Handler to Child Control in Repeater Control
I have a user control which has links buttons as children controls. I use this control to show the parent and child data.<asp:Repeater id="Repeater" runat="server" OnItemDataBound="Repeater_ItemDataBound"> <ItemTemplate> <asp:Panel id="Panel" runat="server"> <asp:Label id="Name" runat="server" Font-Bold></asp:Label> <div class="Small"> <asp:Panel id="EditPanel" runat="server"> <asp:Label ID="lblids" runat="server" Visible...

Repeater control in another repeater control
Hi, I want Repeater control in another repeater control but it is not working Code : <asp:Repeater ID=CourseMaster Runat=server > <ItemTemplate> <table border=0 cellpadding=0 cellspacing=0 style="font-family:tahoma;font-size:12"> <tr> <td >&nbsp;<b</b></td> </tr> <tr> <td> <asp:repeater ID="CourseDetails" Runat=server> <ItemTemplate> <table > <tr> <td </td> <td ></td> </tr> </table> </ItemTemplate> </asp:repeater></td> </tr> </table> </ItemTemplate> </asp:Repeater> But one error occurs Name 'CourseDetails' is not declared. CourseDetails is the name of the second repeater Help Pls CourseDetails control belongs to the outer repeater control so it does not exist untill the outer repeater has some items created. You can access the inner repeater only going through the Item property of the outer repeater given it has some items created. Let me know if you need more info. Post your code in that case.B...

Run an event whose control is located in Data Presentation Controls
Hey, How can we fire an event which belongs to such as a button which is located in Data Presentation Controls such as a gridview.For example : Assume that my page contains a gridview control which is contains a button and the button name comes from database by gridview control but i wanna fire button control's own event independently of the GridView. Thanks and Regards.I am not a perfect programmer, but i have perfect programmers' habits [ i think so :)] Hi:   You can use CommandArgument to distinguish different buttons in the same column: <asp:Button ID="Button2&...

working with the textbox textchanged event when the textbox is a template field in a gridview
How can specify the correct row to work on when using the textchanged event for a textbox in a girdview template below is the code   Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Dim x As String x = CType(gv1.Rows(0).FindControl("textbox2"), TextBox).Text End Sub   So if i type 123 in the first textbox which is in row 0 it will store the text of that textbox in string x.  But as you can see i have to but a 0 in the Rows().  What Can I do so that it knows automitallcy what row textbox i have just typed in.  i tried to d...

Make a TextBox TextChanged event bubble to GridViews RowCommand event?
Hi, I need some help with this, though I do not really know if its possible, I surely hope so. At a page, I have a GridView control, in one of the itemtemplates, I have a TextBox. What I want to accomplish is that when a user enters/changes a value in the textbox, the page should be posted back and the GridViews RowCommand() event handler should be triggered. Is this possible? I have set the AutoPostBack property of the textbox true, and when I change the value in the textbox the page is posted back, however, the GridViews RowCommand is not triggered. Cheers,, There are 2 ways to solve your problem.  The best and most practicle approach is to use the "OnTextChanged" event for the textbox. Then write your custom code for the method for the OnTextChanged eventhandler. The second and worse approach is to stick with your autopost back event and in the page_load method test for postback events IE (If(Page.IsPostBack){do some code}).  This should be avoided however. Hi:sben: You may use GridViewCommandEventHandler to combine it to your RowCommand() . Check this:http://www.webswapp.com/codesamples/viewsource.aspx?file=~/codesamples/aspnet20/dependentlists/gridview.aspxBest Regards,__________________________________________________Sincerely,Rex LinMicrosoft Online Community SupportThis posting is provided "AS IS" with on warranties, and confers no rights....

HELP: Catch event between Textbox TextChange and Button Click events
Hi, May I ask for an assistance in solving the current issue that I have. Current Setup: 1. Textbox has textchanged event, in that event it populates a dropdown list.2. When the Textbox is set to empty, it would delete the list in the dropdown list.3. Button click would save the values of the textbox and dropdown selection. Problem Scenario: 1. Set Textbox value to empty.2. Cursor is still in the textbox3. User clicks on the button4, TextChanged event is fired.5. Error message panel is not displayedRequired fix: 1. when Textbox value is empty2. cursor is still in the textbox3. user cli...

Problem in invoking event of parent repeater having child repeater and user control
Dear All, The situation is, My webpage has a Repeater(say P1) which contains a usercontrol. This usercontrol has another repeater(say C1), this repeater C1 contains a usercontrol having some dropdownlist with autoppostback property set to true. My problem is that I want to know that how can i get the row number of the repeater P1 when postback is caused by one of the dropdownlist of the usercontrol placed in repeater C1. Thanks, Nitin  Hi,In your case, it cannot be done directly upto my knowledge. Any I am having a solution. For that you need to set in your page EnableEventV...

- My repeater control itemcommand event not firing when hosting a user control in itemtemplate
I declare a user control including a label and a textbox. Then in my containg aspx page, I register the UC and add a repeater control like this: The tagname is: Practice and tagprefix is: UC Here is the aspx html code of the containig page:                                     <asp:Repeater ID="rep" Runat="server">                                                 <ItemTemplate>                                                             <uc:practice id="itpractice" runat="server"></uc:practice>                                        ...

events in a repeater control
I have an aspx page that uses a repeater control. The itemtemplate and alternateitem template both contain an html table. There are several controls in the tablecells, now the problem is the following: I need to dynamically create a row, some times (depending on the user being logged in or not) the row should show and some times it will not. I tried first defining the road in the html code, with a dynamically assigned css class (it would be hidden when I don't want to show the row), but the problem is that it leaves a blank and doesn't look right. So I decided to use the ItemC...

events for a textbox control
hi frnds.... i am using vs2005,,asp.net,vb.net coding.... Please help me in this query... How can i get the 'enter' event for a textbox.... thank u in advance What o u mean by enter event? Do u mean to say that u need to set the focus. If so then try, TextBox1.Focus()Please click "Mark As Answer" if this hepled in solving your problem. hi you mean enter key event. if it is, there is not enter key event in asp.net alike windows application. if you hit enter key the page will postback.....RegardsRajesh Hi,set autopost property to true for that textbox N.P...

textchanged event in the textbox
Hi all, I want to handle the ontextchanged event of the textbox which is in my itemtemplate. Can any one help in solving this? Regards, Ramesh Rathi Assign the even handler method name to the OnTextChanged attribute of the text box?<asp:TemplateField HeaderText="Name">  <ItemTemplate>    <asp:TextBox runat="server" ID="txt" OnTextChanged="txt_TextChanged" />  </ItemTemplate></asp:TemplateField>In the code-behind:protected void txt_TextChanged(object sender, EventArgs e){}Mark replies as answer...

textChanged event of textbox
on every character entered in textbox,i want to search and display similar records from database for the characters entered, Hi, Take a look @ Andy Smith's ComboBox HTH K B ShajudeenAreYaar.comDubai, United Arab Emirates. tell me one thing do you want to do like the MSDN help index page? mp417feed the creative machine yes,u r right You must take a look at DbCombo It nice and it professional!!!~ Firoz AnsariPune, Indiahttp://www.firozansari.comWhy product testing is important?...

TextBox and TextChanged event
I have an asp:TextBox on my page and I've set the OnChange attribute and implemented the TextChanged event handler and it works fine most of the time. However, if I clear the contents of the text box and then start entering a new value, and I get a drop down list of recently entered values starting with the same letters that I've just entered in the textbox, and I then select one of items from the drop down list the TextChanged event doesn't fire. Anyway to get around this? Disable the drop down list from ever appearing? Thanks Jon you prbly have autofill on...go to tools ->...

TextBox.TextChanged Event
Hi all, I have a text box on a form and I'm trying to capture the TextChanged event, which I am able to do. The problem is, if someone REMOVES all the text in the box and then leaves the text box the event does not occur. Is this by design? Why would the event fire ONLY if there is text in the box? Did you include 'Autopostback=True'? I did it with your scenario, and it worked for me.David WierMCP/ASPInsiderASPNet101.com - where to look first!Please Vote for ASPNet101 - 'Best Community Resource'!Control Grouper - easily control properties for multiple controls with one co...

textbox TextChanged event
Hello, I have a TextBox. If a user enters data (ie. b123 ) it should automatically change it to upper case (B123) I tried to put code in the TextChanged event but it does not seem to respond at all. How can I get this to work? private void TextBoxStaDocNum2_TextChanged(object sender, System.EventArgs e) { TextBoxStaDocNum.Text.ToUpper; } Thanks a lot for your help Chris Are you expecting the event to fire immediately when the text is changed?  It's a server-side event, so the only way it can fire is when the server is recontacted - i.e., when the Web Form is posted back. ...

textBox control in Repeater
I have this <ItemTemplate>                <%#DataBinder.Eval(Container.DataItem, "Labeltext")%>                <br />                <asp:TextBox ID="txtAnswer" runat="server" TextMode="SingleLine" Width="150px"></asp:TextBox>           ...

TextBox Control Events
Hi There, I have 13 years of programming experience in DESKTOP applications like Oracle, VB and Delphi....But I am new to ASP.NET 2.0 so just cant get my mind off from desktop programming...my question is that when we develop a web based application how can I trap TEXTBOX control events like  'On Enter Key', LostFocus, GotFocus and other important events...as I am in a middle of developing a Accounting System so suppose If I want user to take input in all CAPS and If the focus go on next TextBox Control i want to do something or when I leave the TextBox control I want to do som...

Web resources about - TextChanged event of TextBox in Repeater - asp.net.presentation-controls

Index - 2,000 Things You Should Know About WPF
Below is a list of all posts created so far for the 2,000 Things You Should Know About WPF blog. Total number of posts = 1,077 Animation #7 - ...

Issue 11889003: Fixing ESC in instant-extended. - Code Review
+asvitkine because I changed your fix of crbug.com/172382 by ensuringOmniboxEditModel::OnChanged is never called when an INSTANT_COMPLETE_REPLACEcomes ...

... without the benefit of actual translation into another language.Usually the text has accents added to the characters or the form of the textchanged ...

Developing Sugar Activities using HTML5: Part #2
When you click on an image, you could hear the pronunciation of the word. Here is the Enyo source code for this page: enyo.kind({ name: "TestArt4Apps", ...

PasswordTextBox for Silverlight 2 Beta 2
The standard TextBox control that is built into Silverlight 2 Beta 2 is a bit lacking and is missing alot of features that we have become accustomed ...

The Retail Email Blog: Website Relaunches
Disney Store has relaunched the website and tweaked theiremail template. Unlike some website relaunch emails that are bizarrely light ondetails, ...

LiveCode 5.5 - RunRev
This release of LiveCode brings near feature parity on Android and iOS. Build your app for one mobile platform, and just run it on the other ...

Silverlight for PHP Developers
A Microsoft browser plug-in might seem an odd target for the PHP developer, more used to working with open source platforms such as Linux, Apache ...

Using MVVM with the AutoCompleteTextBox in Silverlight 4
... the code can be found below. public class ImmediateUpdateBehavior : Behavior { protected override void OnAttached() { AssociatedObject.TextChanged ...

The Retail Email Blog: Black Friday
Disney Store has relaunched the website and tweaked theiremail template. Unlike some website relaunch emails that are bizarrely light ondetails, ...

Resources last updated: 3/17/2016 7:30:37 AM