need help determining the return value of a generated js onChange event

Discussion in 'ASP .Net' started by MDBloemker, May 11, 2004.

  1. MDBloemker

    MDBloemker Guest

    can anyone help me fathom out how to use this bit of code:

    Public Class Utilities
    Public Shared Sub CreateConfirmBox(ByRef txt As WebControls.TextBox,
    _
    ByVal strMessage As String)
    txt.Attributes.Add("onchange", "return confirm('" & strMessage &
    "');")
    End Sub
    End Class

    invoked thusly:
    Utilities.CreateConfirmBox(Me.txtDelete,  "Are you sure you want to
    delete (this uses the Utilities Class)?")

    Works great. However....

    The ever-so-helpful page I stole this from explains:
    The client-side JavaScript confirm(string) function displays a confirm
    message box, displaying the string message passed into the function.
    Recall that confirm message boxes provide both "OK" and "Cancel"
    buttons. If the "OK" button is clicked, confirm() returns true; if
    "Cancel" is clicked, it returns false. The return keyword is used to
    return the result of the confirm message box. If a value of false is
    returned, then the form is not submitted.

    What it's NOT telling me is how to get the value returned by the
    javascript confirm(). I've already determined that I can't assign some
    sort of flag to either the call or the class. This would be ever so
    helpful if I can just figure out how to get the true/false value so
    that I can handle program flow.

    If the answer turns out to be blindingly obvious, I'll be very annoyed
    at myself, but at the same time eternally grateful to whomsoever turns
    the light on. Thanks!

    MDBloemker
    MDBloemker, May 11, 2004
    #1
    1. Advertising

  2. MDBloemker

    Ben Dewey Guest

    This code would work on a submit button onclick event. because by default
    if you return true the submit continues and if you return false the submit
    terminates. Now, if you use it on a textbox, you will not get the same
    results.

    What are you confirming a delete of on the change event of a textbox?

    There are a couple work arounds if you were trying to do this on the
    onchange event, but I would need some more info on what exactly you are
    trying to do. ie. Are you planning on submitting a form when the change
    something, or are you planning on not letting them change the value in a
    text field.

    "MDBloemker" <> wrote in message
    news:...
    > can anyone help me fathom out how to use this bit of code:
    >
    > Public Class Utilities
    > Public Shared Sub CreateConfirmBox(ByRef txt As WebControls.TextBox,
    > _
    > ByVal strMessage As String)
    > txt.Attributes.Add("onchange", "return confirm('" & strMessage &
    > "');")
    > End Sub
    > End Class
    >
    > invoked thusly:
    > Utilities.CreateConfirmBox(Me.txtDelete, "Are you sure you want to
    > delete (this uses the Utilities Class)?")
    >
    > Works great. However....
    >
    > The ever-so-helpful page I stole this from explains:
    > The client-side JavaScript confirm(string) function displays a confirm
    > message box, displaying the string message passed into the function.
    > Recall that confirm message boxes provide both "OK" and "Cancel"
    > buttons. If the "OK" button is clicked, confirm() returns true; if
    > "Cancel" is clicked, it returns false. The return keyword is used to
    > return the result of the confirm message box. If a value of false is
    > returned, then the form is not submitted.
    >
    > What it's NOT telling me is how to get the value returned by the
    > javascript confirm(). I've already determined that I can't assign some
    > sort of flag to either the call or the class. This would be ever so
    > helpful if I can just figure out how to get the true/false value so
    > that I can handle program flow.
    >
    > If the answer turns out to be blindingly obvious, I'll be very annoyed
    > at myself, but at the same time eternally grateful to whomsoever turns
    > the light on. Thanks!
    >
    > MDBloemker
    >
    Ben Dewey, May 11, 2004
    #2
    1. Advertising

  3. MDBloemker

    Guest

    I finally figured it out shortly after I posted. It does nothing to
    help with program flow, which what I was looking for in the first
    place. It merely provides a true/false method to determine whether or
    not to set off the _textchanged event.

    What I was looking for was a large, in-your-face ok/cancel popup that
    would control program flow. The example I posted was actually
    misleading, sorry; the original example was for a delete action from a
    button, I'm really trying to intercept the change event on a textbox.
    This particular textbox is only enabled when the user elects to add a
    new record. It's the key field, and must therefore be unique. After
    input, I want the process to quickly query the table to see if that
    key already exists. The in-your-face popup with ok/cancel is primarly
    a user expectation; they're used to grey boxes popping up and blocking
    their way when they do something wrong. Ideally, the message would be
    "Click OK to overwrite the existing record, Cancel to return to the
    main screen".

    With this control, I found I can give them the popup, which would be
    nice except it would always fire onchange, even if the input were
    acceptable. That's why it was originally a button-click-event, duh.
    And even then I would only have two choices as regards program flow:
    fire the _textChanged event or don't.

    Are there any other alternatives I can pursue, or should I just expect
    to re-train my users to look for error messagesthat require decisons
    on a certain part of the form?


    On Tue, 11 May 2004 13:46:16 -0400, "Ben Dewey"
    <> wrote:

    >This code would work on a submit button onclick event. because by default
    >if you return true the submit continues and if you return false the submit
    >terminates. Now, if you use it on a textbox, you will not get the same
    >results.
    >
    >What are you confirming a delete of on the change event of a textbox?
    >
    >There are a couple work arounds if you were trying to do this on the
    >onchange event, but I would need some more info on what exactly you are
    >trying to do. ie. Are you planning on submitting a form when the change
    >something, or are you planning on not letting them change the value in a
    >text field.
    , May 12, 2004
    #3
    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. Chris  Ashley

    Onchange event - need to click out?

    Chris Ashley, Dec 6, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    695
    Karl Seguin
    Dec 6, 2005
  2. Nathan Sokalski
    Replies:
    4
    Views:
    4,136
    Nathan Sokalski
    Mar 11, 2006
  3. Greenhorn
    Replies:
    15
    Views:
    794
    Keith Thompson
    Mar 6, 2005
  4. NewmanBT

    need help with onChange event

    NewmanBT, May 17, 2004, in forum: Javascript
    Replies:
    1
    Views:
    139
    NewmanBT
    May 18, 2004
  5. Robert Carlson
    Replies:
    2
    Views:
    125
    Richard Cornford
    Sep 14, 2004
Loading...

Share This Page