Solved

OK CANCEL MSGBOX

Posted on 2006-07-13
6
366 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:phil301
Comment Utility
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
Comment Utility
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
Comment Utility
But where you getting the same error earlier when you used "JavaScript" instead of "VBScript"
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

743 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

17 Experts available now in Live!

Get 1:1 Help Now