473,699 Members | 2,433 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=JavaSc ript runat=server>"
alertScript &= "alert('" & msg & "');"
alertScript &= "</script>"

RegisterClientS criptBlock(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 33683
In Page Load event:

btnSubmit.Attri butes.Add("lang uage", "javascript ")
btnSubmit.Attri butes.Add("OnCl ick", "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 CausesValidatio n = True for your submit button...

Greg

"Dave" <da************ *************** **@stic.net> wrote in message
news:ey******** ******@TK2MSFTN GP10.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=JavaSc ript runat=server>"
alertScript &= "alert('" & msg & "');"
alertScript &= "</script>"

RegisterClientS criptBlock(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@DON T_SPAM_ME_hotma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
In Page Load event:

btnSubmit.Attri butes.Add("lang uage", "javascript ")
btnSubmit.Attri butes.Add("OnCl ick", "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 CausesValidatio n = 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%******** ********@TK2MSF TNGP12.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@DON T_SPAM_ME_hotma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
In Page Load event:

btnSubmit.Attri butes.Add("lang uage", "javascript ")
btnSubmit.Attri butes.Add("OnCl ick", "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 CausesValidatio n = 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@DON T_SPAM_ME_hotma il.com> wrote in message
news:u1******** ******@tk2msftn gp13.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%******** ********@TK2MSF TNGP12.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@DON T_SPAM_ME_hotma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
In Page Load event:

btnSubmit.Attri butes.Add("lang uage", "javascript ")
btnSubmit.Attri butes.Add("OnCl ick", "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 CausesValidatio n = 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******** **********@TK2M SFTNGP11.phx.gb l...
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@DON T_SPAM_ME_hotma il.com> wrote in message
news:u1******** ******@tk2msftn gp13.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%******** ********@TK2MSF TNGP12.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@DON T_SPAM_ME_hotma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
In Page Load event:

btnSubmit.Attri butes.Add("lang uage", "javascript ")
btnSubmit.Attri butes.Add("OnCl ick", "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 CausesValidatio n = 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.publi c.dotnet.framew ork.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******** ******@TK2MSFTN GP10.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@DON T_SPAM_ME_hotma il.com> wrote in message
news:u1******** ******@tk2msftn gp13.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%******** ********@TK2MSF TNGP12.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@DON T_SPAM_ME_hotma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
> In Page Load event:
>
> btnSubmit.Attri butes.Add("lang uage", "javascript ")
> btnSubmit.Attri butes.Add("OnCl ick", "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 CausesValidatio n = 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@DON T_SPAM_ME_hotma il.com> wrote in message
> news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
>> In Page Load event:
>>
>> btnSubmit.Attri butes.Add("lang uage", "javascript ")
>> btnSubmit.Attri butes.Add("OnCl ick", "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 CausesValidatio n = 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
2336
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 need to: 1. Click a submit button on an asp page, calling another page that saves the contents of that form to a database and then displays
1
2648
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 Page_Load(object sender, System.EventArgs e) { if(! Page.IsPostBack)
0
3714
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 javascript confirm popup to this checkbox server control to prevent this event from firing if the cancel button is checked in the js confirm window. In the example below, I am able to accomplish this using the input type=checkbox but without the...
7
1699
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 need to prompt the users with a modal box (with "Yes" and "Cancel" button on it); 2) When the user clicks "Yes" button, I need to do some further processing. If "Cancel" is clicked, of course, stops doing anything; 3) Now the problems are: -...
12
2130
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 press the Yes button. If I take off the Javascript event, the checkbox works fine. XferToDefault.Attributes.Add("onclick", "return confirm('Are you sure you want copy these entries?');") <asp:CheckBox ID="XferToDefault" AutoPostBack="true"...
5
3068
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. 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
4
10021
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" and a "delete" node. I have the functionality of the edit and delete working fine, my issue is now however that I cannot seem to find a way to add an "onclick" event that fires a confirm box. I've tried this method.. treenode.Text = "<a...
6
3283
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 Page_Load event: Dim iCount As Int32 Dim sClientSideValidate As New StringBuilder iCount = dgReport.Items.Count For i As Int32 = 2 To iCount + 1
1
108746
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 button anyways, if the user ventures away from your page then they wouldn't have this button at their disposal. The main reason people ask how to control or disable the back button is because they have a need to control sensitive (and/or) dynamic web...
0
8687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9174
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9034
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8914
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8883
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.