469,946 Members | 1,782 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Using Javascript confirm box in vb.net web app

Hello all,

I have been able to use a Javascript alert box in my vb.net web application,
for example:

Dim msg As String = "Hello, world."
Dim alertScript As String = "<script language=JavaScript runat=server>"
alertScript &= "alert('" & msg & "');"
alertScript &= "</script>"

RegisterClientScriptBlock(sKey, alertScript)

----------------------------------------------------------------------

Now I'm a little more ambitious, and would like to use a confirm box and
capture the return value of the dialog.

Is there a simple way to do this?
Thanks very much in advance,

Dave
Nov 20 '05 #1
8 33241
In Page Load event:

btnSubmit.Attributes.Add("language", "javascript")
btnSubmit.Attributes.Add("OnClick", "return confirm('Are you sure?');")

Page will not submit if Cancel is clicked. Things get harry if you have a
validator on the page, and CausesValidation = True for your submit button...

Greg

"Dave" <da*****************************@stic.net> wrote in message
news:ey**************@TK2MSFTNGP10.phx.gbl...
Hello all,

I have been able to use a Javascript alert box in my vb.net web application, for example:

Dim msg As String = "Hello, world."
Dim alertScript As String = "<script language=JavaScript runat=server>"
alertScript &= "alert('" & msg & "');"
alertScript &= "</script>"

RegisterClientScriptBlock(sKey, alertScript)

----------------------------------------------------------------------

Now I'm a little more ambitious, and would like to use a confirm box and
capture the return value of the dialog.

Is there a simple way to do this?
Thanks very much in advance,

Dave

Nov 20 '05 #2
Thanks, Greg. Though I'm a web development newbie, I can see how that would
work. But is there a way to capture the return value?

I want to be able to branch and process some code for each return value.

Thanks,

David
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
In Page Load event:

btnSubmit.Attributes.Add("language", "javascript")
btnSubmit.Attributes.Add("OnClick", "return confirm('Are you sure?');")

Page will not submit if Cancel is clicked. Things get harry if you have a
validator on the page, and CausesValidation = True for your submit button...
Greg

[snip
]> >
Now I'm a little more ambitious, and would like to use a confirm box and
capture the return value of the dialog.

Is there a simple way to do this?
Thanks very much in advance,

Dave

Nov 20 '05 #3
There is only two possible return values, no? True or False. If it was
false that page doesn't get submitted. So you server side code will never
run.

If you want to run code server-side when than answer is false, then I don't
think you can use a javascript confirm box.

Greg
"Dave" <da*****************************@stic.net> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
Thanks, Greg. Though I'm a web development newbie, I can see how that
would
work. But is there a way to capture the return value?

I want to be able to branch and process some code for each return value.

Thanks,

David
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
In Page Load event:

btnSubmit.Attributes.Add("language", "javascript")
btnSubmit.Attributes.Add("OnClick", "return confirm('Are you sure?');")

Page will not submit if Cancel is clicked. Things get harry if you have
a
validator on the page, and CausesValidation = True for your submit

button...

Greg

[snip
]> >
> Now I'm a little more ambitious, and would like to use a confirm box
> and
> capture the return value of the dialog.
>
> Is there a simple way to do this?
>
>
> Thanks very much in advance,
>
> Dave
>


Nov 20 '05 #4
Thanks, Greg.

True or False - that's the intuitive guess, but I don't know what the values
are for sure, because their code is a black box when you use Page_Load.
E.g., it could be an Error Code rather than T/F. Or, being a Sub, it may
not even have a return value.

More importantly, whatever the return value is, I don't know how to capture
it in a VB variable that I declare. To use an analogy, in VB6 you can use
these statements:

Ret = Msgbox("Click a response", vbOKCancel)
If Ret = vbOK then
'User hit OK
Else If Ret = vbCancel
'User hit Cancel
End If

And you've captured the return value into the VB variable "Ret".

My question is - How can I achieve this in vb.net using Javascript's confirm
box? Or if I can't, is there a simple construct that I can use instead?

Dave

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
There is only two possible return values, no? True or False. If it was
false that page doesn't get submitted. So you server side code will never
run.

If you want to run code server-side when than answer is false, then I don't think you can use a javascript confirm box.

Greg
"Dave" <da*****************************@stic.net> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
Thanks, Greg. Though I'm a web development newbie, I can see how that
would
work. But is there a way to capture the return value?

I want to be able to branch and process some code for each return value.

Thanks,

David
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
In Page Load event:

btnSubmit.Attributes.Add("language", "javascript")
btnSubmit.Attributes.Add("OnClick", "return confirm('Are you sure?');")

Page will not submit if Cancel is clicked. Things get harry if you have a
validator on the page, and CausesValidation = True for your submit

button...

Greg

[snip]
Nov 20 '05 #5
I guess I need a more concrete example of what you want to accomplish.

My understanding of the javascript Confirm box is that it is VERY limited in
what it does. You get OK and Cancel. That's it. If you click OK it
returns true, false otherwise. Now I suppose you could do whatever you want
in javascript with this result clientside (my javascript skills are not so
hot). But, AFAIK, all you can do is prevent your server side code from
executing in regards to ASP.NET.

Now you can get creative using Panels to display or hide different messages
on your web page that have whatever buttons you want on them. But again,
this is all server side and will not appear in a message box. You could try
and fake a message box by displaying your "message box" web page as a pop-up
window (usuing a little js code to launch the window), but this has its own
issues. (Pop up blockers, natuarally will try and prevent your page from
showing)

Greg
"Dave" <da*****************************@stic.net> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
Thanks, Greg.

True or False - that's the intuitive guess, but I don't know what the
values
are for sure, because their code is a black box when you use Page_Load.
E.g., it could be an Error Code rather than T/F. Or, being a Sub, it may
not even have a return value.

More importantly, whatever the return value is, I don't know how to
capture
it in a VB variable that I declare. To use an analogy, in VB6 you can use
these statements:

Ret = Msgbox("Click a response", vbOKCancel)
If Ret = vbOK then
'User hit OK
Else If Ret = vbCancel
'User hit Cancel
End If

And you've captured the return value into the VB variable "Ret".

My question is - How can I achieve this in vb.net using Javascript's
confirm
box? Or if I can't, is there a simple construct that I can use instead?

Dave

Nov 20 '05 #6
Well, I thought posted a reply to this Friday, but I can't find it, so I'll
try again. In VB6, I used to do this kind of thing all the time:

ret = MsgBox("Click a response", vbOKCancel)
If ret = vbOK Then
'User hit OK
Else If ret = vbCancel Then
'User hit Cancel
End If

And the return value has been captured into the declared variable "ret".

This is the functionality I'm trying to achieve, but I don't know how to in
vb.net.

It's hard to believe I'm the only programmer that would want or need to do
this.

Thanks, everybody.

Dave

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
There is only two possible return values, no? True or False. If it was
false that page doesn't get submitted. So you server side code will never
run.

If you want to run code server-side when than answer is false, then I don't think you can use a javascript confirm box.

Greg
"Dave" <da*****************************@stic.net> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
Thanks, Greg. Though I'm a web development newbie, I can see how that
would
work. But is there a way to capture the return value?

I want to be able to branch and process some code for each return value.

Thanks,

David
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
In Page Load event:

btnSubmit.Attributes.Add("language", "javascript")
btnSubmit.Attributes.Add("OnClick", "return confirm('Are you sure?');")

Page will not submit if Cancel is clicked. Things get harry if you have a
validator on the page, and CausesValidation = True for your submit

button...

Greg

[snip
]> >
> Now I'm a little more ambitious, and would like to use a confirm box
> and
> capture the return value of the dialog.
>
> Is there a simple way to do this?
>
>
> Thanks very much in advance,
>
> Dave
>



Nov 20 '05 #7
Dave, you may want to try microsoft.public.dotnet.framework.aspnet group if
you don't get any more takers.

I suppose you could redirect to a different web page (or the same with a
different query string indicating your response) from within a javascript
function based on the result of your confirm box.

I am still having a hard time grasping what you are trying to do. A lot of
people use this kind of thing for prompting if you want to delete a row from
a datagrid. (for example) If you click Ok, it deletes. If you click
Cancel, nothing happens. (ie, no code runs) If you need code to run, I
think you need to make your buttons be server side buttons on the page (not
a js Confirm box). Or try something like I mentioned with javascript client
side function.

Hopefully somebody with some fresh ideas jumps in.

Good luck,
Greg
"Dave" <da*****************************@stic.net> wrote in message
news:uM**************@TK2MSFTNGP10.phx.gbl...
Well, I thought posted a reply to this Friday, but I can't find it, so I'll try again. In VB6, I used to do this kind of thing all the time:

ret = MsgBox("Click a response", vbOKCancel)
If ret = vbOK Then
'User hit OK
Else If ret = vbCancel Then
'User hit Cancel
End If

And the return value has been captured into the declared variable "ret".

This is the functionality I'm trying to achieve, but I don't know how to in vb.net.

It's hard to believe I'm the only programmer that would want or need to do
this.

Thanks, everybody.

Dave

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
There is only two possible return values, no? True or False. If it was
false that page doesn't get submitted. So you server side code will never
run.

If you want to run code server-side when than answer is false, then I

don't
think you can use a javascript confirm box.

Greg
"Dave" <da*****************************@stic.net> wrote in message
news:e%****************@TK2MSFTNGP12.phx.gbl...
Thanks, Greg. Though I'm a web development newbie, I can see how that
would
work. But is there a way to capture the return value?

I want to be able to branch and process some code for each return value.
Thanks,

David
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> In Page Load event:
>
> btnSubmit.Attributes.Add("language", "javascript")
> btnSubmit.Attributes.Add("OnClick", "return confirm('Are you sure?');")>
> Page will not submit if Cancel is clicked. Things get harry if you

have> a
> validator on the page, and CausesValidation = True for your submit
button...
>
> Greg
>
[snip
]> >
> > Now I'm a little more ambitious, and would like to use a confirm box> > and
> > capture the return value of the dialog.
> >
> > Is there a simple way to do this?
> >
> >
> > Thanks very much in advance,
> >
> > Dave
> >



Nov 20 '05 #8
Upon further research, I find your method works fine. I didn't understand
the internal mechanics of submitting pages before, but this method takes
care of what I need with no problem.

So thanks again, Greg, your advice was very helpful.

Dave
[snip
]> > > > "Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
> news:%2****************@TK2MSFTNGP09.phx.gbl...
>> In Page Load event:
>>
>> btnSubmit.Attributes.Add("language", "javascript")
>> btnSubmit.Attributes.Add("OnClick", "return confirm('Are you sure?');") >>
>> Page will not submit if Cancel is clicked. Things get harry if you

have
>> a
>> validator on the page, and CausesValidation = True for your submit
> button...
>>
>> Greg

[snip]
Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Muhammad Abdullah | last post: by
reply views Thread by Chris Fink | last post: by
7 posts views Thread by Tigger | last post: by
12 posts views Thread by tshad | last post: by
4 posts views Thread by tfsmag | last post: by
6 posts views Thread by Peter Afonin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.