OnTextChanged prefire?

G

Guest

I think I already know the answer to this but here goes. I've read the other
postings but no solutions for this.
If a user enters a textbox, there is no 'onenter', etc. to control firing
off a sub, etc. We have OnTextChanged. But it doesn't fire until focus is
placed somewhere else.
The issue is that on my form if a user changes a textbox but goes to 'Save'
the form, the 'Save' button gets the focus and fires event OnTextChanged but
stops its true calling to submit form. The user has to press it twice and
that's just plain unacceptable.

Any workarounds? or missing something? Thanx.
 
R

recoil

I am not sure exactly what you are asking for but you can easily create
your own PostBack event either by using a secondary invisible code and
then attaching it manually using ControlName.Attributes.Add method or
you could register a PostBackHandler and handle it that way also. After
that it merely becomes a matter of finding out exactly what javascript
event you want it fired upon.
e.g.
myServerTextBox.Attributes.Add("onchange",
GetPostBackClientEvent(InvisibleControl, ""); or alternately
myServerTextBox.Attributes.Add("onchange",
GetPostBackClientEvent(myServerTextBox, "onchange");
And then either through your IPostBackHandler or by hacking and
looking at the EventArgument in the Textbox's postback handler event

String EventArgument = this.Page.Request["__EVENTARGUMENT"];

if (EventArgument==null) { EventARgument = ""; }
EventArgument = EventArgument.ToLower();
switch(EventArgument)
{
case "onchange" .... break;
case "onlosefocus": ... break;
}

etc
I would definitely see if what you can do can be done without a
postback event as postback events upon key clicks is extremely annoying
and probably one of the biggest bastardizations brought to the net by
asp.net
 
B

bruce barker

i assume you have autopostback set on the text control. this works by client
script catching the onchange event and firing a form submit. if the user
clicks on the submit button, the browser detects that a form submit is in
progress and doesn't fire the submit button submit, and as the submit is in
progress, the submit values cannot change.

the workaround is not too complex, just a little client code. on textbox,
onchange use a timer to fire the __dopostback. when the button is clicked
set a variable that a postback is started. in the timer routine do nothing
if the submit button fired.

register as startup script (change names).

<script>

window.cancelAutoSubmit = false;
document.getElementById('textbox1').onchange = function () {
window.setTimeout("if (!window.cancelAutoSubmit )
__doPostBack('textbox1')");
}
document.getElementById('button1').onclick = function () {
window.cancelAutoSubmit = true;
}
</script>

though i'd look at using autopost on a text field as a suspect coding style.

-- bruce (sqlwork.com)

| I think I already know the answer to this but here goes. I've read the
other
| postings but no solutions for this.
| If a user enters a textbox, there is no 'onenter', etc. to control firing
| off a sub, etc. We have OnTextChanged. But it doesn't fire until focus is
| placed somewhere else.
| The issue is that on my form if a user changes a textbox but goes to
'Save'
| the form, the 'Save' button gets the focus and fires event OnTextChanged
but
| stops its true calling to submit form. The user has to press it twice and
| that's just plain unacceptable.
|
| Any workarounds? or missing something? Thanx.
 
G

Guest

what exactly do you mean "suspect coding style"?
Do you offer another solution for stamping an area on a form based on the
user making changes.

i.e. I have 6 textboxes that each resepctively have their own 'changed by
and when' label (thus saved) on one form. So if a user makes a change in one
of these 6 textboxes the 'OnTextChanged' then sets the label with the user id
and date/time. These same labels are displayed if a user enters the form in
'modify' mode.

I'm open to ideas if you have solutions.
 
G

Guest

I tried to respond yesterday but the MSDN website crapped out again, I love
this site but it's stablity is getting worse.

Question: Why isn't OnTextChanged really 'Onchange'? It's really 'lostfocus'
becasue it doesn't fire until focus is lost!
I'm running a routine to update a label field (see response trail for more
info). But since the firing of this routine occurs once the button is
pressed, thus losing focus on a textbox, it stops the 'submit'.

I really need some sort of true onchange. I've tried onfocus but that's not
really correct since the user might enter but not change. Please read the
trail for more detail. I'd love to get your take on what I'm trying to
accomplish, thanx.
 
Joined
Mar 31, 2008
Messages
1
Reaction score
0
=?Utf-8?B?Q2hyaXM=?=,
Did you ever find a solution to this problem? I am having the same problem and can't figure it out?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top