Cannot close dialog from link inside same dialog - returns error
Hi I have a issue which is very common but I searched it and tried every possible solution but nothing worked.
My problem is I have a classic asp page default.asp, I defined a dialog in it + a div "mydiv" and a button which opens the defined dialog in "mydiv" and loads default2.asp in this dialog.
Default2.asp is also a form to submit and has many links to products, when user clicks on one of those links it updates info to its parent page "Default.asp" and tries to close Default2.asp (the dialog)
It fails to close the dialog giving error
[
cannot
call methods on dialog prior to initialization; attempted to call method '
close
']
Please let me know what is wrong here. I asked this to various forums but no success yet.
The code is here
------------------------------------------------ Default.asp code starts from here --------------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <script src="/JQuery/jquery-1.9.1.js"></script>
- <script src="/JQuery/jquery-ui.js"></script>
- <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
- <script>
- $(document).ready(function(){
- var MyDlg = $( "#mydiv" );
- MyDlg.dialog({
- autoOpen: false,
- closeOnEscape: true,
- resizable: true,
- draggable: true,
- modal: true,
- width: 300,
- height: 400,
- buttons: {
- Cancel: function() {
- MyDlg.dialog( "close" );
- }
- }
- });
- $("#Opendlg").click(function() {
- MyDlg.load("Default2.asp").dialog("open");
- });
- });
- </script>
- </head>
- <body>
- This is a test form-1
- <br><br>
- <%
- Dim FName, LName
- FName = Request.form("fname")
- LName = Request.form("lname")
- Response.write("The First name was := " & FName & " and Last name was:=" & LName )
- %>
- <br><br>
- <form ID=Form1 method="post" action="Default.asp">
- First Name: <input type="text" name="fname"><br>
- Last Name: <input type="text" name="lname"><br><br>
- <input type="submit" value="Submit">
- </form>
- <br><br>
- <input type="button" ID="Opendlg" value="Open Dialog"/>
- <div id="mydiv" title="Product Wizard" >
- </div>
- </body>
- </html>
----------------------------------------------------- Default2.asp Starts from here -----------------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <title>Default2.asp</title>
- <script src="/JQuery/jquery-1.9.1.js"></script>
- <script src="/JQuery/jquery-ui.js"></script>
- <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
- <script type="text/javascript">
- $(function() {
- $('#Form2').submit(function(evt) {
- evt.preventDefault();
- $.ajax({
- url: "Default2.asp",
- type: 'POST',
- data: $(this).serialize(),
- success: function(result) {
- $('#mydiv').html(result);
- }
- });
- });
- });
- function closeThis()
- {
- // $("#mydiv").hide();
- $("#mydiv").dialog("close");
- }
- </script>
- </head>
- <body>
- This is Default2.asp file
- <a href="JavaScript:closeThis();">Close This Dialog</a>
- <br><br>
- <%
- Dim Name, Address
- Name = Request.form("Name")
- Address = Request.form("address")
- Response.write("The Name was " & Name & " and Address was " & Address )
- %>
- <br><br>
- <form ID=Form2 >
- Name: <input type="text" name="Name"><br>
- Address: <input type="text" name="address"><br><br>
- <input type="submit" value="Submit">
- This is just a test
- </form>
- </body>
- </html>