Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

OK CANCEL MSGBOX

Posted on 2006-07-13
6
Medium Priority
?
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

705 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