Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > need help determining the return value of a generated js onChange event

Reply
Thread Tools

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

 
 
MDBloemker
Guest
Posts: n/a
 
      05-11-2004
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

 
Reply With Quote
 
 
 
 
Ben Dewey
Guest
Posts: n/a
 
      05-11-2004
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: m...
> 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
>



 
Reply With Quote
 
 
 
 
mdb@hotmail.com
Guest
Posts: n/a
 
      05-12-2004
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.


 
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
Determining the Browser and event.keyCode vs. event.which Nathan Sokalski ASP .Net 4 03-11-2006 06:36 AM
Determining the Browser and event.keyCode vs. event.which Nathan Sokalski ASP .Net Building Controls 4 03-11-2006 06:36 AM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
OnChange event extracting value from Select incorrectly Robert Carlson Javascript 2 09-14-2004 09:42 PM
need help with onChange event NewmanBT Javascript 1 05-18-2004 01:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57