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.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
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" <Chris@.discussions.microsoft.com> wrote in message
news:F01B0012-F7CA-47DF-9C0F-5DF9835274D7@.microsoft.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.
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 i
d
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 clie
nt
> 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 i
n
> 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 styl
e.
> -- bruce (sqlwork.com)
> "Chris" <Chris@.discussions.microsoft.com> wrote in message
> news:F01B0012-F7CA-47DF-9C0F-5DF9835274D7@.microsoft.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 firin
g
> | off a sub, etc. We have OnTextChanged. But it doesn't fire until focus i
s
> | 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 an
d
> | that's just plain unacceptable.
> |
> | Any workarounds? or missing something? Thanx.
>
>
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.
"recoil@.community.nospam" 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
>
Thursday, March 29, 2012
OnTextChanged prefire?
Labels:
asp,
enters,
net,
ontextchanged,
otherpostings,
prefire,
solutions,
textbox,
user
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment