469,903 Members | 2,138 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Using javascript confirm in .aspx

I'm tearing my hair out over this one.

Using VS 2003, inline (not code-behind), vb.net.

I have a button (btnClear) that calls a vb routine that goes into sql server
and truncates a table.

What I want is to call a javascript confirm box upon clicking the button
that asks the user if he's sure he wants to do the deed. I have tried so
many permutations and combinations of RegisterClientScriptBlock, <input
onclick=, runat=server, btnClear.Attributes.Add("onclick",".....") that my
head is spinning.

I just can't seem to get the confirm return value to the vb.net code, the
server-side, or whatever the correct term is. After Googling for help, I
saw many examples of javascript code that is easy to understand and use, but
none that works together with vb.net code.

Can anyone provide a clear method of doing this?
Thanks in advance,

Dave
Nov 21 '05 #1
5 2915
If you add this little JS snippet to your button: onClick="return
confirm('Are you sure you want to delete this report?');".

When the button is clicked, a Yes/No dialog should open. If the user clicks
No, then the script will return false, and nothing should happen. This is
automatic, and you don't need to check for the return value. If they click
Yes, then the button should fire.

"Dave" <da*****************************@stic.net> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...
I'm tearing my hair out over this one.

Using VS 2003, inline (not code-behind), vb.net.

I have a button (btnClear) that calls a vb routine that goes into sql server and truncates a table.

What I want is to call a javascript confirm box upon clicking the button
that asks the user if he's sure he wants to do the deed. I have tried so
many permutations and combinations of RegisterClientScriptBlock, <input
onclick=, runat=server, btnClear.Attributes.Add("onclick",".....") that my
head is spinning.

I just can't seem to get the confirm return value to the vb.net code, the
server-side, or whatever the correct term is. After Googling for help, I
saw many examples of javascript code that is easy to understand and use, but none that works together with vb.net code.

Can anyone provide a clear method of doing this?
Thanks in advance,

Dave

Nov 21 '05 #2
Richard,

Thank you very much for your response. Your answer may be part of the
solution, but I still can't get it to do everything needed. First when you
say "If you add ...", I assume you mean something like this:

<td>
<input OnClick="return confirm('Are you sure you want to delete this
report?');"
type="button" value="Clear" runat="server" id="btnClearVisits">
</td>

I do ge the desired dialog box, but the desired code does not fire. My code
looks something like this:

Sub btnClearVisits(ByVal sender As System.Object, ByVal e As
System.EventArgs)
ClearVisits()
end sub

sub ClearVisits()

[...]

dim sql As String = "TRUNCATE TABLE tblVisits "
Dim NumAffected As Integer = cmd.ExecuteNonQuery()

[...]
end sub

Do you see anything obvious I'm missing or doing wrong? It appears the sub
ClearVisits() never executes. Before I got the idea of confirming with the
user, the sub ClearVisits() worked fine.

Thanks again.

Dave
"Richard Dudley" <ri**@rjdudley.com> wrote in message
news:e9**************@TK2MSFTNGP14.phx.gbl...
If you add this little JS snippet to your button: onClick="return
confirm('Are you sure you want to delete this report?');".

When the button is clicked, a Yes/No dialog should open. If the user
clicks
No, then the script will return false, and nothing should happen. This is
automatic, and you don't need to check for the return value. If they
click
Yes, then the button should fire.

"Dave" <da*****************************@stic.net> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...
I'm tearing my hair out over this one.

Using VS 2003, inline (not code-behind), vb.net.

I have a button (btnClear) that calls a vb routine that goes into sql

server
and truncates a table.

What I want is to call a javascript confirm box upon clicking the button
that asks the user if he's sure he wants to do the deed. I have tried so
many permutations and combinations of RegisterClientScriptBlock, <input
onclick=, runat=server, btnClear.Attributes.Add("onclick",".....") that
my
head is spinning.

I just can't seem to get the confirm return value to the vb.net code, the
server-side, or whatever the correct term is. After Googling for help, I
saw many examples of javascript code that is easy to understand and use,

but
none that works together with vb.net code.

Can anyone provide a clear method of doing this?
Thanks in advance,

Dave


Nov 21 '05 #3
If you want the 'intended' way rather than having to fudge it, have you
considered whether any of the '~Validator' objects will work? Don't know
whether they will suit your purpose but have a look at this link
http://aspnet.4guysfromrolla.com/articles/073102-1.aspx
this is Scott Mitchell's website, basically anything I've ever wanted to
know about asp.net I've managed to find there.

alternatively one more code line to try:
<td>
<input OnClick="if(confirm('Are you sure you want to delete this
report?')) btnClearVisits_Click();"
type="button" value="Clear" runat="server" id="btnClearVisits">
</td>
might be way off but then again it might work...

"Dave" wrote:
Richard,

Thank you very much for your response. Your answer may be part of the
solution, but I still can't get it to do everything needed. First when you
say "If you add ...", I assume you mean something like this:

<td>
<input OnClick="return confirm('Are you sure you want to delete this
report?');"
type="button" value="Clear" runat="server" id="btnClearVisits">
</td>

I do ge the desired dialog box, but the desired code does not fire. My code
looks something like this:

Sub btnClearVisits(ByVal sender As System.Object, ByVal e As
System.EventArgs)
ClearVisits()
end sub

sub ClearVisits()

[...]

dim sql As String = "TRUNCATE TABLE tblVisits "
Dim NumAffected As Integer = cmd.ExecuteNonQuery()

[...]
end sub

Do you see anything obvious I'm missing or doing wrong? It appears the sub
ClearVisits() never executes. Before I got the idea of confirming with the
user, the sub ClearVisits() worked fine.

Thanks again.

Dave
"Richard Dudley" <ri**@rjdudley.com> wrote in message
news:e9**************@TK2MSFTNGP14.phx.gbl...
If you add this little JS snippet to your button: onClick="return
confirm('Are you sure you want to delete this report?');".

When the button is clicked, a Yes/No dialog should open. If the user
clicks
No, then the script will return false, and nothing should happen. This is
automatic, and you don't need to check for the return value. If they
click
Yes, then the button should fire.

"Dave" <da*****************************@stic.net> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...
I'm tearing my hair out over this one.

Using VS 2003, inline (not code-behind), vb.net.

I have a button (btnClear) that calls a vb routine that goes into sql

server
and truncates a table.

What I want is to call a javascript confirm box upon clicking the button
that asks the user if he's sure he wants to do the deed. I have tried so
many permutations and combinations of RegisterClientScriptBlock, <input
onclick=, runat=server, btnClear.Attributes.Add("onclick",".....") that
my
head is spinning.

I just can't seem to get the confirm return value to the vb.net code, the
server-side, or whatever the correct term is. After Googling for help, I
saw many examples of javascript code that is easy to understand and use,

but
none that works together with vb.net code.

Can anyone provide a clear method of doing this?
Thanks in advance,

Dave



Nov 21 '05 #4
Thanks, Bonj, that's an interesting idea. I know a little about Validators,
but hadn't thought about using them here. One of my goals is to write more
platform-independent code, and so using a Validator control will be one of
the later solutions I try.

I'm still curious about solving this problem in a straightforward way,
because it will enlighten some concepts for me I need to know as a
programmer, and will be useful for the future. I think the answer is
simple, but you need to know more about the ins and outs of client-server
than I currently know.

Dave

"Bonj" <Bo**@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com...
If you want the 'intended' way rather than having to fudge it, have you
considered whether any of the '~Validator' objects will work? Don't know
whether they will suit your purpose but have a look at this link
http://aspnet.4guysfromrolla.com/articles/073102-1.aspx
this is Scott Mitchell's website, basically anything I've ever wanted to
know about asp.net I've managed to find there.

alternatively one more code line to try:
<td>
<input OnClick="if(confirm('Are you sure you want to delete this
report?')) btnClearVisits_Click();"
type="button" value="Clear" runat="server" id="btnClearVisits">
</td>
might be way off but then again it might work...

"Dave" wrote:
Richard,

Thank you very much for your response. Your answer may be part of the
solution, but I still can't get it to do everything needed. First when
you
say "If you add ...", I assume you mean something like this:

<td>
<input OnClick="return confirm('Are you sure you want to delete this
report?');"
type="button" value="Clear" runat="server" id="btnClearVisits">
</td>

I do ge the desired dialog box, but the desired code does not fire. My
code
looks something like this:

Sub btnClearVisits(ByVal sender As System.Object, ByVal e As
System.EventArgs)
ClearVisits()
end sub

sub ClearVisits()

[...]

dim sql As String = "TRUNCATE TABLE tblVisits "
Dim NumAffected As Integer = cmd.ExecuteNonQuery()

[...]
end sub

Do you see anything obvious I'm missing or doing wrong? It appears the
sub
ClearVisits() never executes. Before I got the idea of confirming with
the
user, the sub ClearVisits() worked fine.

Thanks again.

Dave
"Richard Dudley" <ri**@rjdudley.com> wrote in message
news:e9**************@TK2MSFTNGP14.phx.gbl...
> If you add this little JS snippet to your button: onClick="return
> confirm('Are you sure you want to delete this report?');".
>
> When the button is clicked, a Yes/No dialog should open. If the user
> clicks
> No, then the script will return false, and nothing should happen. This
> is
> automatic, and you don't need to check for the return value. If they
> click
> Yes, then the button should fire.
>
> "Dave" <da*****************************@stic.net> wrote in message
> news:up**************@TK2MSFTNGP15.phx.gbl...
>> I'm tearing my hair out over this one.
>>
>> Using VS 2003, inline (not code-behind), vb.net.
>>
>> I have a button (btnClear) that calls a vb routine that goes into sql
> server
>> and truncates a table.
>>
>> What I want is to call a javascript confirm box upon clicking the
>> button
>> that asks the user if he's sure he wants to do the deed. I have tried
>> so
>> many permutations and combinations of RegisterClientScriptBlock,
>> <input
>> onclick=, runat=server, btnClear.Attributes.Add("onclick",".....")
>> that
>> my
>> head is spinning.
>>
>> I just can't seem to get the confirm return value to the vb.net code,
>> the
>> server-side, or whatever the correct term is. After Googling for
>> help, I
>> saw many examples of javascript code that is easy to understand and
>> use,
> but
>> none that works together with vb.net code.
>>
>> Can anyone provide a clear method of doing this?
>>
>>
>> Thanks in advance,
>>
>> Dave
>>
>>
>
>


Nov 21 '05 #5
I added this - btnClearVisits.Attributes.add("OnClick","javascrip t:return
confirm('Are you sure you want to delete this report?');") - to my
Page_Load, removed it from the <input> tag, and it worked great after I
removed some CS101 errors I had put in previously.

I appreciate the responses to my problem.

Dave

"Richard Dudley" <ri**@rjdudley.com> wrote in message
news:e9**************@TK2MSFTNGP14.phx.gbl...
If you add this little JS snippet to your button: onClick="return
confirm('Are you sure you want to delete this report?');".

When the button is clicked, a Yes/No dialog should open. If the user
clicks
No, then the script will return false, and nothing should happen. This is
automatic, and you don't need to check for the return value. If they
click
Yes, then the button should fire.

"Dave" <da*****************************@stic.net> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...
I'm tearing my hair out over this one.

Using VS 2003, inline (not code-behind), vb.net.

I have a button (btnClear) that calls a vb routine that goes into sql

server
and truncates a table.

What I want is to call a javascript confirm box upon clicking the button
that asks the user if he's sure he wants to do the deed. I have tried so
many permutations and combinations of RegisterClientScriptBlock, <input
onclick=, runat=server, btnClear.Attributes.Add("onclick",".....") that
my
head is spinning.

I just can't seem to get the confirm return value to the vb.net code, the
server-side, or whatever the correct term is. After Googling for help, I
saw many examples of javascript code that is easy to understand and use,

but
none that works together with vb.net code.

Can anyone provide a clear method of doing this?
Thanks in advance,

Dave


Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Chris Fink | last post: by
7 posts views Thread by Tigger | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.