Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > OnTextChanged prefire?

Reply
Thread Tools

OnTextChanged prefire?

 
 
=?Utf-8?B?Q2hyaXM=?=
Guest
Posts: n/a
 
      03-15-2005
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.
 
Reply With Quote
 
 
 
 
recoil@community.nospam
Guest
Posts: n/a
 
      03-15-2005
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

 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      03-15-2005
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)

"Chris" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| 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.


 
Reply With Quote
 
=?Utf-8?B?Q2hyaXM=?=
Guest
Posts: n/a
 
      03-15-2005
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.

"bruce barker" wrote:

> 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)
>
> "Chris" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> | 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.
>
>
>

 
Reply With Quote
 
=?Utf-8?B?Q2hyaXM=?=
Guest
Posts: n/a
 
      03-16-2005
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.

"(E-Mail Removed)" wrote:

> 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
>
>

 
Reply With Quote
 
fiteclubforever fiteclubforever is offline
Junior Member
Join Date: Mar 2008
Posts: 1
 
      03-31-2008
=?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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OnTextChanged not firing?? =?Utf-8?B?TmVpbA==?= ASP .Net 3 08-29-2005 08:54 AM
JavaScript for OnTextChanged event. Alex Nitulescu ASP .Net 1 03-05-2005 11:11 AM
onTextChanged not firing kbrandl@gmail.com ASP .Net 3 02-02-2005 03:25 PM
OnTextChanged and DataGridItems =?Utf-8?B?TmVpbA==?= ASP .Net 2 10-06-2004 02:13 PM
textbox's state does not persist if onTextChanged not defined Henri ASP .Net 6 08-06-2004 02:08 PM



Advertisments