473,809 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript Confirm()

Hi all,

Can any one direct me in how to use javascript confirm() function when
a condition is met from codebehind. I don't want to attach this to a
button. When I submit the page, I want to check some business rules,
and based on the response from the database, if the response is Yes, I
need to display a confirmation alert to user. When the user clicks ok,
then I should take an action, if not, exit out of the subroutine.

Below is the script I'm using in the Submit_Click() subroutine.

If Trim(Message) <"" Then
Dim strScript As String = "<script
language=JavaSc ript>"
strScript += "confirm("" " & Trim(Message) &
""");"
strScript += "</script>"
If (Not
Page.IsStartupS criptRegistered ("clientScript" )) Then
Page.RegisterSt artupScript("cl ientScript",
strScript)
End If
End If

In the above code, I'm getting a message from the Sql database into
Message variable, and showing that to the user.
But I don't have a way to track what an user have selected from the
confirmation alert box.

Any help is appreciated.
Thanks.

Dec 20 '06 #1
7 5212
Hi,

shil wrote:
Hi all,

Can any one direct me in how to use javascript confirm() function when
a condition is met from codebehind. I don't want to attach this to a
button. When I submit the page, I want to check some business rules,
and based on the response from the database, if the response is Yes, I
need to display a confirmation alert to user. When the user clicks ok,
then I should take an action, if not, exit out of the subroutine.

Below is the script I'm using in the Submit_Click() subroutine.

If Trim(Message) <"" Then
Dim strScript As String = "<script
language=JavaSc ript>"
The "language" attribute is deprecated. You should use
type="text/javascript" instead.
strScript += "confirm("" " & Trim(Message) &
""");"
The "confirm" method returns a boolean. It's true if the user clicked
Yes, and false if he clicked No. You need to save this value in a variable

strScript += "var bAnswer = confirm(""" & Trim(Message) & """);"

strScript += "</script>"
If (Not
Page.IsStartupS criptRegistered ("clientScript" )) Then
Page.RegisterSt artupScript("cl ientScript",
strScript)
End If
End If

In the above code, I'm getting a message from the Sql database into
Message variable, and showing that to the user.
But I don't have a way to track what an user have selected from the
confirmation alert box.
Once the user's answer is saved in the "bAnswer" variable, you need to
transmit it to the server. There are many ways to do that.

- The easiest is probably to put the variable in a hidden form field and
then submit the form (using JavaScript). On the server, read the hidden
form field's value.

- You can use a query string, for example:

top.location = "mypage.aspx?an swer=" + ( bAnswer ? "true" : "false" );

These two ways cause a callback to the server, so the page will be
refreshed.

A third way, which won't cause a callback, is to use some kind of Ajax.
In your case, a simple call using XmlHttpRequest would be sufficient. Or
else, you can use a web method.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Dec 20 '06 #2
This link may help you to setup message and action communication between
server and client:
http://www.usableasp.net/DeveloperPa...rAndClient.htm

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"shil" <jo******@gmail .comwrote in message
news:11******** **************@ 48g2000cwx.goog legroups.com...
Hi all,

Can any one direct me in how to use javascript confirm() function when
a condition is met from codebehind. I don't want to attach this to a
button. When I submit the page, I want to check some business rules,
and based on the response from the database, if the response is Yes, I
need to display a confirmation alert to user. When the user clicks ok,
then I should take an action, if not, exit out of the subroutine.

Below is the script I'm using in the Submit_Click() subroutine.

If Trim(Message) <"" Then
Dim strScript As String = "<script
language=JavaSc ript>"
strScript += "confirm("" " & Trim(Message) &
""");"
strScript += "</script>"
If (Not
Page.IsStartupS criptRegistered ("clientScript" )) Then
Page.RegisterSt artupScript("cl ientScript",
strScript)
End If
End If

In the above code, I'm getting a message from the Sql database into
Message variable, and showing that to the user.
But I don't have a way to track what an user have selected from the
confirmation alert box.

Any help is appreciated.
Thanks.

Dec 20 '06 #3
store the answer in a hidden field:

document.getEle mentById('field id').value = confirm('ok');

where fieldid is the id of the hidden field

-- bruce (sqlwork.com)

shil wrote:
Hi all,

Can any one direct me in how to use javascript confirm() function when
a condition is met from codebehind. I don't want to attach this to a
button. When I submit the page, I want to check some business rules,
and based on the response from the database, if the response is Yes, I
need to display a confirmation alert to user. When the user clicks ok,
then I should take an action, if not, exit out of the subroutine.

Below is the script I'm using in the Submit_Click() subroutine.

If Trim(Message) <"" Then
Dim strScript As String = "<script
language=JavaSc ript>"
strScript += "confirm("" " & Trim(Message) &
""");"
strScript += "</script>"
If (Not
Page.IsStartupS criptRegistered ("clientScript" )) Then
Page.RegisterSt artupScript("cl ientScript",
strScript)
End If
End If

In the above code, I'm getting a message from the Sql database into
Message variable, and showing that to the user.
But I don't have a way to track what an user have selected from the
confirmation alert box.

Any help is appreciated.
Thanks.
Dec 20 '06 #4
No doubt you will have to store these in a hidden field if you don't want to
use a lot of Ajax here. As you said you don't want to attach this to a
button. So here's an example of handling a return value such as in
confirm(message ), and using those values in server side code.
http://www.codeproject.com/aspnet/Cl...nteraction.asp

"shil" <jo******@gmail .comwrote in message
news:11******** **************@ 48g2000cwx.goog legroups.com...
Hi all,

Can any one direct me in how to use javascript confirm() function when
a condition is met from codebehind. I don't want to attach this to a
button. When I submit the page, I want to check some business rules,
and based on the response from the database, if the response is Yes, I
need to display a confirmation alert to user. When the user clicks ok,
then I should take an action, if not, exit out of the subroutine.

Below is the script I'm using in the Submit_Click() subroutine.

If Trim(Message) <"" Then
Dim strScript As String = "<script
language=JavaSc ript>"
strScript += "confirm("" " & Trim(Message) &
""");"
strScript += "</script>"
If (Not
Page.IsStartupS criptRegistered ("clientScript" )) Then
Page.RegisterSt artupScript("cl ientScript",
strScript)
End If
End If

In the above code, I'm getting a message from the Sql database into
Message variable, and showing that to the user.
But I don't have a way to track what an user have selected from the
confirmation alert box.

Any help is appreciated.
Thanks.
Dec 20 '06 #5
http://www.aspkey.net/aspkey/_blog/i...th=8&year=2006

"shil" <jo******@gmail .comwrote in message news:11******** **************@ 48g2000cwx.goog legroups.com...
Hi all,

Can any one direct me in how to use javascript confirm() function when
a condition is met from codebehind. I don't want to attach this to a
button. When I submit the page, I want to check some business rules,
and based on the response from the database, if the response is Yes, I
need to display a confirmation alert to user. When the user clicks ok,
then I should take an action, if not, exit out of the subroutine.

Below is the script I'm using in the Submit_Click() subroutine.

If Trim(Message) <"" Then
Dim strScript As String = "<script
language=JavaSc ript>"
strScript += "confirm("" " & Trim(Message) &
""");"
strScript += "</script>"
If (Not
Page.IsStartupS criptRegistered ("clientScript" )) Then
Page.RegisterSt artupScript("cl ientScript",
strScript)
End If
End If

In the above code, I'm getting a message from the Sql database into
Message variable, and showing that to the user.
But I don't have a way to track what an user have selected from the
confirmation alert box.

Any help is appreciated.
Thanks.

Dec 22 '06 #6
Hi everyone,

I still can't find a solution to my problem.
can any one help me?
As I explained I can't register the event to button on page load
because I have to show the confirmation to user only after checking the
database. If the user click on Yes, I want to track that value and
continue in the server side script with out resubmitting the page.

Thanks.

Jan 2 '07 #7
Not sure exactly what you are asking.
What are you checking in the database?
Are you loading records and the conformation button depends on records being
present or a certain value?
Are you having problems registering the event on the button?
Are you looking for a way to call server side code from client side code
like using AJax or Ajax.Net?

Regards,
Brian K. Williams
"shil" <jo******@gmail .comwrote in message
news:11******** **************@ i12g2000cwa.goo glegroups.com.. .
Hi everyone,

I still can't find a solution to my problem.
can any one help me?
As I explained I can't register the event to button on page load
because I have to show the confirmation to user only after checking the
database. If the user click on Yes, I want to track that value and
continue in the server side script with out resubmitting the page.

Thanks.

Jan 15 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2653
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)
9
4926
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work fine from a link. The button does bring up the popup window, but when I press the links on the page, it doesn't return or close the window. ****************************************************************************
7
2025
by: TJS | last post by:
javascript "confirm" fires after deletion instead of before deletion. how do I get this to stop the processing ? code ================== Sub ShowAlert(ByVal s As string) RegisterClientScriptBlock("CSP-showconfirm-function", _ "<s"+"cript language=""JavaScript"">" & vbCrLf & _
12
2139
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"...
3
4522
by: TJ | last post by:
Hi, I would like to ask something to user after user submits the form... I know I can ask user whehter they want to submit the form or not using client-script code such as onClick or onSubmit by adding into attributes collections... My problem is a little bit different than that... I would like to ask user something after submission is done
8
33708
by: Dave | last post by:
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>"
4
10026
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
2532
by: den 2005 | last post by:
Hi everybody, Question 1: How do you set the values from server-side to a client-side control or how do you execute a javascript function without a button click event? Question 2: How do you get response from a Confirm() popup window to uncheck all server-side checkboxes placed in a panle of a web user control? I am using ASP.Net 2.0, Thanks. Need info...
8
4036
by: rn5a | last post by:
I have gone through a no. of posts in this NewsGroup regarding my problem but alas, couldn't come across one which would have helped me in resolving the issue. My problem is this: An ASPX Form has a Button. When the Button is clicked, I want a JavaScript confirm dialog to pop-up with the options 'OK' & 'Cancel'. I have done this using the following code: Sub Page_Load(....) btnClick.Attributes.Add("OnClick", "javascript:return...
1
108783
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
9721
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
9600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10633
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
10376
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
10375
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
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
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...
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3011
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.