Solved

OK CANCEL MSGBOX

Posted on 2006-07-13
6
368 Views
Last Modified: 2011-09-20
I am attempting to create a "Do you really want to cancel" type button in my ASP.NET web page. I have created the code below. When I step through the code, it seems to work fine. It uses the logic and determines which button was pushed and applies the logic.

I would like for the page to remain the same ("no action taken") when the "cancel" button is pressed.


Any help would be greatly appreciated.



When I press the "cancel button" it gives me an error when it trys to exit the "ABORT" subroutine. "A runtime error has occured, do you wish to debug?"  "Line 2 Error: Syntax Error"

1  <script language='javascript'>
2
3  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5  <html xmlns="http://www.w3.org/1999/xhtml" >
6  <head><title>


        Response.Write("<script language='javascript'>")
        Dim RETVAL As Integer
        RETVAL = MsgBox("ARE YOU SURE YOU WANT TO ABORT TEST?", 1, "ABORT TEST")
        If RETVAL = 2 Then
            Exit Sub
        Else
        End If
        Response.Write("</script>")
0
Comment
Question by:phil301
  • 3
  • 3
6 Comments
 
LVL 17

Expert Comment

by:gops1
ID: 17099720
Is it necessary to use the above, I mean Respose.write?? Thoug you have opened a Javascript tag, but VBScript is written inside.

Have a look at this sample code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
      <title>Untitled</title>
      <script language="javascript">
            function doCancel(){
                  var answer=confirm("Are you sure of cancelling?");
                  if(answer){
                        alert("Put your actions for cancelling");
                  }else{
                        alert("Cancel Aborted");
                  }
            }
      </script>
</head>

<body>
<input type="button" value="Cancel" onclick="doCancel();">
</body>
</html>
0
 

Author Comment

by:phil301
ID: 17100613
I am new to javascript, I guess I am a little confused.

The code below is written in the visual basic control of the button in asp.net, not in the code behind HTML section. I am not sure how to incorporate the code you wrote in the visual basic side and not the html side.

 vb does not seem to accept anything without the "response.write" first. Here is the entire sub if that helps any.



Protected Sub btnAbort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAbort.Click

        Response.Write("<script language='javascript'>")
        Dim RETVAL As Integer
        RETVAL = MsgBox("ARE YOU SURE YOU WANT TO ABORT TEST?", 1, "ABORT TEST")
        If RETVAL = 2 Then
            Exit Sub
        Else
        End If
        Response.Write("</script>")

        Dim connectionstring As String = _
                                             "Initial Catalog=BAE;Data Source=Ambas0002\BAEWEB;UID=allusers;PWD=bae2006"
        Dim connection As New SqlConnection(connectionstring)
        connection.Open()
        Dim strSQL As String
        strSQL = "INSERT INTO EXAM_3B (Gun_Number,Inspector_Name,Stop_Pressure,Stop_Shop_Temp,Revision_Number,Date_Of_Entry) VALUES ('" & Session("Gun_Number") & "','" & Session("Inspector_Name") & "', -1 ,-1,'" & Session("RevNumC") + 1 & "','" & Session("FTime") & "')"
        Dim Com As New System.Data.SqlClient.SqlCommand(strSQL, connection)
        Com.ExecuteNonQuery()
        connection.Close()
        Response.Redirect("Exam3Abort.aspx")

    End Sub
0
 
LVL 17

Accepted Solution

by:
gops1 earned 125 total points
ID: 17100676
Use VBScript instead of JavaScript:

       Response.Write("<script language='VBScript'>")
        Dim RETVAL As Integer
        RETVAL = MsgBox("ARE YOU SURE YOU WANT TO ABORT TEST?", 1, "ABORT TEST")
        If RETVAL = 2 Then
            Exit Sub
        Else
        End If
        Response.Write("</script>")
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:phil301
ID: 17100780
I inserted the last code you sent, and it still gives me the original error.


A runtime error has occured, do you wish to debug?"  "Line 2 Error: Syntax Error"

1  <script language='javascript'>
2
3  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5  <html xmlns="http://www.w3.org/1999/xhtml" >
6  <head><title>

0
 

Author Comment

by:phil301
ID: 17101001
Thanks for you help, I figured it out. The code should be as follows:

Response.Write("<script language='VBScript'>")
        Dim RETVAL As Integer
        RETVAL = MsgBox("ARE YOU SURE YOU WANT TO ABORT TEST?", 1, "ABORT TEST")
        If RETVAL = 2 Then
            Response.Write("</script>")
            Exit Sub

        End If
        Response.Write("</script>")


The error was coming in because I was trying to exit sub before I used the   Response.Write("</script>")
0
 
LVL 17

Expert Comment

by:gops1
ID: 17101358
But where you getting the same error earlier when you used "JavaScript" instead of "VBScript"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now