1

I have a repeater that places 600+ textboxes filled with data on my page. A typical user will edit several of these.

I would like the OnTextChanged event to run when I hit a save button, but it's not working.

All of my textboxes have the property OnTextChanged="TextBoxChanged" When my user selects the save button

<asp:Button ID="SaveChangesBtn" CssClass="SaveAndNextBtn" runat="server" 
            Text="Save Changes" onclick="SaveChangesBtnClick" />

I would like the TextBoxChanged event to run for each textbox that has been changed. How can I implement this?

4
  • Is the TextChanged event raised only once after you've clicked the button? Commented Sep 12, 2012 at 21:36
  • I have no textchanged anywhere. I just have the TextBoxChanged function that is never called Commented Sep 12, 2012 at 21:39
  • Do you rebind the repeater on every postback or have you wrapped the databinding stuff (as you should) in a !IsPostback-check? Commented Sep 12, 2012 at 21:41
  • That actually did the trick. I didn't know about that. Thanks! Please make your comment an answer so I can select it Commented Sep 12, 2012 at 21:45

2 Answers 2

4

Do you rebind the repeater on every postback or have you wrapped the databinding stuff (as you should) in a !IsPostback-check?

if(!IsPostBack)
    DataBindRepeater();

If you databind web-databound controls on postbacks, all changes are lost and events won't be triggered.

Sign up to request clarification or add additional context in comments.

Comments

0

I'm afraid OnTextChanged isn't quite what you are looking for then. OnTextChanged fires after a control has been entered, changed and then left (lost focus), so it fires when you select the next object.

you could use the OnTextChanged to accumulate a list of the IDs of the textboxes with changed contents, and then when you save, just loop over all the changed boxes to perform whatever task you like.

3 Comments

Only true with AutoPostBack (not default). Otherwise the OnTextChanged event handler would be called on the next postback(.f.e on button click).
It actually seems to be only calling the TextBoxes on the save button now. I'm not sure why it isn't calling it out of focus, but I'm not complaining because this is the way I want it.
@proseidon: That's what i've commented above, only if you set AutoPostBack="True" it will post back immediately as soon as the user has changed the Text and the focus is lost(javascript blur event). But the serverside TextChanged event is triggered anyway later on the next roundtrip to server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.