Using Javascript confirm box in vb.net web app

D

Dave

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
 
G

Greg Burns

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
 
D

Dave

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 said:
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
]> >
 
G

Greg Burns

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 said:
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 said:
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
]> >
 
D

Dave

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 said:
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
[snip]
 
G

Greg Burns

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
 
D

Dave

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 said:
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 said:
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 said:
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
 
G

Greg Burns

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 said:
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 said:
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 said:
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
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
 
D

Dave

Greg,

I think it's time for Plan C - learn this stuff better than I currently know
it. I just thought there was something simple and flexible. I see the
simple way, and I see the flexible way - unfortunately, they're not the same
way.

Thanks again for taking the time to help me out here, Greg. I'll muddle
through.

Dave
 
D

Dave

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
[snip]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top