473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

OnTextChanged prefire?

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.
Nov 19 '05 #1
4 2569
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

Nov 19 '05 #2
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" <Ch***@discussions.microsoft.com> wrote in message
news:F0**********************************@microsof t.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.
Nov 19 '05 #3
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" <Ch***@discussions.microsoft.com> wrote in message
news:F0**********************************@microsof t.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.

Nov 19 '05 #4
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.

"re****@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

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Henri | last post by:
Very strange problem : if I write: <asp:TextBox runat="server" id="myBox" /> the control's ViewState stays always empty, so it loses its properties if it's not always displayed. But if I...
3
by: Neil | last post by:
Hi, I have a datagrid containing a number of item templates, inside of these item templates I have various controls like the textbox. The user is able to edit all the fields on the datagrid at...
2
by: Neil | last post by:
Hi, I currently have a datagrid with template columns containing textboxes etc. The textboxes are in the item template so the whole grid is editable by default, I then have a general update...
3
by: kbrandl | last post by:
On my page, there is a textbox at the top that contains a date -- and a fully-editable datagrid below (each row in the datagrid contains an editable textbox, along with some other controls). The...
1
by: Alex Nitulescu | last post by:
Hi. I have created a web-based file manager. Now I'd like to watch a folder for changes, and when a change occurs I'd like to refresh my page. Okay. So I have created a FileSystemWatcher set on...
1
by: mdipiet | last post by:
I've got a form that is supposed to validate data entry from a bar code scanner. The scanner is set up to add a carriage return at the end of the data in the barcode, which should fire the...
4
by: MattB | last post by:
Hi. I'm working on an intranet application that requires a user to input information about themselves. I have a user control with a couple of textboxes that I want the user to enter their weight...
0
by: RajS | last post by:
Hi All, I am trying to update datagrid, onTextchanged event, I dont know how to do this. please shed some light or any examples. Here is the code I am wrestling with. OnTextChanged event of...
1
by: Fred Dag | last post by:
As far as I can work out when using the OnTextChanged event I cannot get the TextBox and Labels values when the event fires as they are populated by a <asp:repeater and so don't have values. If...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.