I posted this on the asp.net group, also. I wasn't sure whether this was an
asp.net problem or a javascript problem.
I have a page that was originally created from a program I found on the net
that works well as an html page.
It brings up a modal popup window that I have been trying to work out for
days now and this was the closest I have been able to come.
I added a little asp.net code and an asp.net button and cannot get it to
work with that button. It seems to break the javascript code.
The page works fine with or without the asp.net code (as long as the asp.net
button is not pushed).
This works fine (as before) until I press the asp.net button. I am opening
alert boxes in various locations that all fire until the asp.net button is
pushed. From that time, all links and buttons will bring up the alert box
in the first javascript funtion, but the ModalDialogShow never gets called
or it just ignores it and therefore the popup window never gets called.
Why would the asp.net button cause the Javascript to quit functioning?
Why does the popup window not close when the buttons or links are pressed on
them?
************************************************** ************************************
<%@ Page Language="VB" trace="false" debug="true" AutoEventWireup="true"
ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<html>
<script language=JavaScript>
var ModalDialogWindow;
var ModalDialogInterval;
var ModalDialog = new Object;
ModalDialog.value = '';
ModalDialog.eventhandler = '';
function ModalDialogMaintainFocus()
{
try
{
if (ModalDialogWindow.closed)
{
alert("at ModalDialogWindow.closed");
window.clearInterval(ModalDialogInterval);
eval(ModalDialog.eventhandler);
return;
}
ModalDialogWindow.focus();
}
catch (everything) { }
}
function ModalDialogRemoveWatch()
{
ModalDialog.value = '';
ModalDialog.eventhandler = '';
}
function ModalDialogShow(Title,BodyText,Buttons,EventHandle r)
{
alert("inside ModalDialogShow");
ModalDialogRemoveWatch();
ModalDialog.eventhandler = EventHandler;
var args='width=350,height=125,left=325,top=300,toolba r=0,';
args+='location=0,status=0,menubar=0,scrollbars=1, resizable=0';
ModalDialogWindow=window.open("","",args);
ModalDialogWindow.document.open();
ModalDialogWindow.document.write('<html>');
ModalDialogWindow.document.write('<head>');
ModalDialogWindow.document.write('<title>' + Title + '</title>');
ModalDialogWindow.document.write('<script' + ' language=JavaScript>');
ModalDialogWindow.document.write('function CloseForm(Response) ');
ModalDialogWindow.document.write('{ ');
ModalDialogWindow.document.write(' window.opener.ModalDialog.value =
Response; ');
ModalDialogWindow.document.write(' window.close(); ');
ModalDialogWindow.document.write('} ');
ModalDialogWindow.document.write('</script' + '>');
ModalDialogWindow.document.write('</head>');
ModalDialogWindow.document.write('<body onblur="window.focus();">');
ModalDialogWindow.document.write('<table border=0 width="95%"
align=center cellspacing=0 cellpadding=2>');
ModalDialogWindow.document.write('<tr><td align=left>' + BodyText +
'</td></tr>');
ModalDialogWindow.document.write('<tr><td align=left><br></td></tr>');
ModalDialogWindow.document.write('<tr><td align=center>' + Buttons +
'</td></tr>');
ModalDialogWindow.document.write('</body>');
ModalDialogWindow.document.write('</html>');
ModalDialogWindow.document.close();
ModalDialogWindow.focus();
ModalDialogInterval = window.setInterval("ModalDialogMaintainFocus()",5) ;
}
</script>
<script language=JavaScript>
function YesNoCancel(BodyText,EventHandler)
{
alert("inside YesNoCancel")
var Buttons='';
// Buttons = '<a href=javascript:CloseForm("Yes");>Yes</a> ';
// Buttons += '<a href=javascript:CloseForm("No");>No</a> ';
// Buttons += '<a href=javascript:CloseForm("Cancel");>Cancel</a> ';
Buttons = '<BUTTON onclick="javascript:CloseForm(\'Yes\');"
type="button">Yes</BUTTON> ';
Buttons += '<BUTTON onclick="javascript:CloseForm(\'No\');" type =
"button">No</BUTTON> ';
Buttons += '<BUTTON onclick="javascript:CloseForm(\'Cancel\');" type =
"button">Cancel</BUTTON> ';
ModalDialogShow("Dialog",BodyText,Buttons,EventHan dler);
}
function YesNoMaybe(BodyText,EventHandler)
{
var Buttons='';
Buttons = '<a href=javascript:CloseForm("Yes");>Yes</a> ';
Buttons += '<a href=javascript:CloseForm("No");>No</a> ';
Buttons += '<a href=javascript:CloseForm("Maybe");>Maybe</a> ';
ModalDialogShow("Dialog",BodyText,Buttons,EventHan dler);
}
function YesNoCancelReturnMethod()
{
alert("inside YesNoCancelReturnMethod");
document.getElementById('modalreturn1').value = ModalDialog.value;
ModalDialogRemoveWatch();
}
function YesNoMaybeReturnMethod()
{
document.getElementById('modalreturn2').value = ModalDialog.value;
ModalDialogRemoveWatch();
}
</script>
<script runat="server">
sub page_load(s as object, e as eventArgs)
if not isPostBack then
Button1.Attributes.Add("onclick", "YesNoCancel('Yes, no, or cancel
me','YesNoCancelReturnMethod()');")
end if
end sub
</script>
<BODY >
<table border=1 cellpadding=2 cellspacing=2 align=center width="60%">
<tr><td align=left></td></tr>
<tr><td align=left></td></tr>
<tr><td align=left></td></tr>
<tr>
<td align=left><a href="javascript:YesNoCancel('Yes, no, or cancel
me','YesNoCancelReturnMethod()');">Show Modal #1</a>
1. <input type=text id=modalreturn1 name=modalreturn1
value=''></td>
</tr>
<tr>
<td align=left><a href="javascript:YesNoMaybe('Yes, no, or maybe
me','YesNoMaybeReturnMethod()');">Show Modal #2</a>
2. <input type=text id=modalreturn2 name=modalreturn2
value=''></td>
</tr>
<tr>
<td>
<BUTTON onclick="javascript:YesNoMaybe('Yes, no, or maybe
me','YesNoMaybeReturnMethod()');" type="button">Open Child Window</BUTTON>
</td>
</tr>
</table>
<form runat="server">
<asp:Button ID="Button1" text="submit" runat="server"/>
</form>
</BODY>
</HTML>
************************************************** **********************************
Thanks,
Tom