OnTextChanged prefire?

Discussion in 'ASP .Net' started by =?Utf-8?B?Q2hyaXM=?=, Mar 15, 2005.

  1. 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.
     
    =?Utf-8?B?Q2hyaXM=?=, Mar 15, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?Q2hyaXM=?=

    Guest

    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
     
    , Mar 15, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?Q2hyaXM=?=

    bruce barker Guest

    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" <> wrote in message
    news:...
    | 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.
     
    bruce barker, Mar 15, 2005
    #3
  4. 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" <> wrote in message
    > news:...
    > | 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.
    >
    >
    >
     
    =?Utf-8?B?Q2hyaXM=?=, Mar 15, 2005
    #4
  5. 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.

    "" 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
    >
    >
     
    =?Utf-8?B?Q2hyaXM=?=, Mar 16, 2005
    #5
  6. =?Utf-8?B?Q2hyaXM=?=

    fiteclubforever

    Joined:
    Mar 31, 2008
    Messages:
    1
    =?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?
     
    fiteclubforever, Mar 31, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henri
    Replies:
    6
    Views:
    768
    Henri
    Aug 6, 2004
  2. =?Utf-8?B?TmVpbA==?=

    OnTextChanged not firing??

    =?Utf-8?B?TmVpbA==?=, Oct 5, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    4,295
    =?Utf-8?B?TWFyeUE=?=
    Aug 29, 2005
  3. =?Utf-8?B?TmVpbA==?=

    OnTextChanged and DataGridItems

    =?Utf-8?B?TmVpbA==?=, Oct 6, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    457
    =?Utf-8?B?TmVpbA==?=
    Oct 6, 2004
  4. onTextChanged not firing

    , Feb 1, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    14,410
    =?Utf-8?B?c2FyYQ==?=
    Feb 2, 2005
  5. Alex Nitulescu

    JavaScript for OnTextChanged event.

    Alex Nitulescu, Mar 5, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    53,719
    Wilco Bauwer
    Mar 5, 2005
Loading...

Share This Page