473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 33640
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: fig000 | last post by:
Hi, I'm relatively new to Javascript so please bear with me on what might sound like silly questions. This is what I want to do: I'm working in classic asp (I have to for this project). I...
1
by: Muhammad Abdullah | last post by:
Hi am having some problems with the javascript confirm. i have it working fine on one page and it doesnt even pop up at the other. The code on the working page is, private void...
0
by: Chris Fink | last post by:
My goal is to have an ASP.NET checkbox server tag with it's autopostback set to true, that when clicked will run the checkbox's CheckedChanged event. However, I would like to try to add a...
7
by: Tigger | last post by:
Dear Experts, I am working on ASP.NET. I have got a problem related to the usage of Javascript in ASP.NET. Please help. The story is the following: 1) I am developing an ASP.NET application. I...
12
by: tshad | last post by:
I have the following code that attaches a Javascript confirm box to my checkbox. When I select the checkbox, the window comes up fine, but it never executes the XfertoDefault_Click function when I...
5
by: Dave | last post by:
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. ...
4
by: tfsmag | last post by:
Okay, I have a project management app i'm writing and in the left hand menu i have a treeview control that is populated with each project... in child nodes under each project node I have an "edit"...
6
by: Peter Afonin | last post by:
Hello, I'm creating an application in ASP.NET 1.1. I need to check whether at least one checkbox in my datagrid has been checked. To do this, I'm using Javascript - I'm adding this code to...
1
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.