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" <mdbloemker@hotmail.com> wrote in message
news:20f3a9d9.0405110921.dfcdd93@posting.google.co m...[color=blue]
> 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@hotmail.com[/color]