By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,445 Members | 3,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,445 IT Pros & Developers. It's quick & easy.

Javascript works fine until an asp.net button pushed

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
In article <wd**************@newssvr13.news.prodigy.com>,
ts**********@ftsolutions.com enlightened us with...

The page works fine with or without the asp.net code (as long as the asp.net
button is not pushed).


My guess, not having .net to test this with...

When the button is pushed, the page is submitted to the server and then comes
back to the client, which runs all the javascript all over again.

(put an alert("boom") or something all the way at the beginning and see if it
gets shown twice)

When that happens, the handle to the child window is lost, as all client-side
variables lose their previous values.
That means your child window is calling code that doesn't exist and your
parent window has no reference to the original child. When the child hits the
error (window.opener.ModalDialog.value -- there is no object reference any
more, so there can be no value property), all script stops functioning.
Hence, it won't even self.close.

HTH

--
--
~kaeli~
Local Area Network in Australia:... the LAN down under.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2

P: n/a
Well, for one thing all the Javascript has to be properly terminated
and on one line. Hopefully it is just the way it is posted in the
newsgroup, because if I try and run it cut and paste, I get a bunch of
''unterminated string literal' errors. I am still fix all those
firstly.

(also, I find the Firefox javascript console 100x more powerful then IE
script dialog error box)

Jul 23 '05 #3

P: n/a
I just straighted out all the Javascript as I mentioned above and it
works fine for me using ASP.NET 1.1 and Cassini (in Firefox 1.1 and IE
6)

Jul 23 '05 #4

P: n/a
Are you getting any Javascript errors? I am trying it in IE 6, Firefox
using ASP.NET and Cassini - it seems to work fine, but I did have to
unwrap some of the JavaScript due to what I am assuming is the fault of
the newsreader.

I've found that the JavaScript console in Firefox is 100x more verbose
then IEs script error dialog, so if you are getting a javascript error,
try looking there.

Also, since the popup window doesn't have a status bar, you may be
getting an error and not even know it.

Jul 23 '05 #5

P: n/a
"Brian Munroe" <br************@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
Well, for one thing all the Javascript has to be properly terminated
and on one line. Hopefully it is just the way it is posted in the
newsgroup, because if I try and run it cut and paste, I get a bunch of
''unterminated string literal' errors. I am still fix all those
firstly.

(also, I find the Firefox javascript console 100x more powerful then IE
script dialog error box)


That doesn't matter, unfortunately, as I need to use one that works on all
the browsers.

Tom
Jul 23 '05 #6

P: n/a
I'm not saying anything about cross-browser compatiblity, just that the
Firefox javascript console is more verbose if by chance you are getting
javascript errors.

Jul 23 '05 #7

P: n/a
You know, the way you explained it in the OP makes it sound like once
you click the ASP.NET button, 'everything' stops working, but what I
think you mean 'when you click the ASP.NET button to launch the
dialog, the return value is lost'?

Well, kaeli is correct because the ASP.NET button is posting back and
all the JavaScript is reinitialized and the parent window knows nothing
of the dialog at this point.

As far as a work-around:

1) don't use an ASP.NET control
2) add a 'return false;' to the onclick binding to prevent the button
from submitting:

sub page_load(s as object, e as eventArgs)
if not isPostBack
Button1.Attributes.Add("onclick", "YesNoCancel('Yes, no, or cancel
me','YesNoCancelReturnMethod()'); return false;")
end if
end sub

Jul 23 '05 #8

P: n/a
"Brian Munroe" <br************@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
You know, the way you explained it in the OP makes it sound like once
you click the ASP.NET button, 'everything' stops working, but what I
think you mean 'when you click the ASP.NET button to launch the
dialog, the return value is lost'?

Well, kaeli is correct because the ASP.NET button is posting back and
all the JavaScript is reinitialized and the parent window knows nothing
of the dialog at this point.

As far as a work-around:

1) don't use an ASP.NET control
2) add a 'return false;' to the onclick binding to prevent the button
from submitting:
My problem is that I am trying to set up a popup window that asks the user
what they want to do based on something happening on the page. It is not
just a "do you really want to delete this" type of question where you can
use the standard "confirm" window. The problem with that is you either go
on or do nothing. I need to know whether to do one thing or another in my
asp page. I need to save the value somewhere and then postback to handle the
situation. If I don't use an asp.net control, I am not going to post back.

sub page_load(s as object, e as eventArgs)
if not isPostBack
Button1.Attributes.Add("onclick", "YesNoCancel('Yes, no, or cancel
me','YesNoCancelReturnMethod()'); return false;")
end if
end sub


I thought you said that you made a couple of changes and it was working for
you?

I made a bunch of changes and am trying this with RegisterClientScriptBlock
to see if that works better and it seems to. But I still lose in on
postback, as we mentioned before.

I have the page in:
http://www.payrollworkshop.com/samples/ScriptTest.aspx

The page goes all the way through in IE and you can see the textbox getting
the value YES after the alert box that says:

"inside YesNoCancelReturnMethod"

Then it disapears when the page is posted back.

In Mozilla, I only get to the if test where it is checking if the window is
closed - "ModalDialogWindow.closed" and I get an error:

popupScript += "function ModalDialogMaintainFocus()"
popupScript += "{"
popupScript += " try"
popupScript += " {"
popupScript += " alert(""in ModalDialogMaintainFocus"");"
popupScript += " if (ModalDialogWindow.closed)"

This goes to the Catch clause and gives me:

Type Error: ModalDialogWindow has no properties

And then it dies and window is still open. Not sure why Mozilla has this
problem.

Here is the whole page:

************************************************** *************************
<%@ Page Language="VB" trace="true" debug="true" AutoEventWireup="true"
ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<html>
<head>
<script language="VB" runat="server">
Sub Page_Load( sender as Object,e as EventArgs)
trace.warn("show = " & show.value)
if not IsPostBack then
Button1.Attributes.Add("onclick", "YesNoCancel();")
end if

'Form the script that is to be registered at client side.'
Dim scriptString as String = "<script language=JavaScript> function
DoClick() {"
scriptString += "myForm.show.value='Welcome to Microsoft .NET'}<"
scriptString += "/"
scriptString += "script>"

If(Not IsClientScriptBlockRegistered("clientScript"))
RegisterClientScriptBlock("clientScript", scriptString)
End If

Dim popupScript As String = "<script language='javascript'>"
popupScript += "var ModalDialogWindow;"
popupScript += "var ModalDialogInterval;"
popupScript += "var ModalDialog = new Object;"
popupScript += "ModalDialog.value = 'The Value';"
popupScript += "ModalDialog.eventhandler = '';"
popupScript += "function ModalDialogMaintainFocus()"
popupScript += "{"
popupScript += " try"
popupScript += " {"
popupScript += " alert(""in ModalDialogMaintainFocus"");"
popupScript += " if (ModalDialogWindow.closed)"
popupScript += " {"
popupScript += " alert(""at window.clearInterval"");"
popupScript += " window.clearInterval(ModalDialogInterval);"
popupScript += " alert(""Before ModalDialog.eventhandler"");"
popupScript += " eval(ModalDialog.eventhandler);"
popupScript += " alert(""after ModalDialog.eventhandler"");"
popupScript += " return;"
popupScript += " }"
popupScript += " alert(""Before ModalDialogWindow.focus"");"
popupScript += " ModalDialogWindow.focus(); "
popupScript += " }"
popupScript += " catch (everything) { alert(everything); }"
popupScript += "}"
popupScript += "function ModalDialogRemoveWatch()"
popupScript += "{"
popupScript += " ModalDialog.value = '';"
popupScript += " ModalDialog.eventhandler = '';"
popupScript += "}"
popupScript += "function ModalDialogShow(Title,Buttons) "
popupScript += "{"
popupScript += " alert(""inside YesNoCancel"");"
popupScript += " ModalDialogRemoveWatch();"
popupScript += " alert(""Before ModalDialogWindow open"");"
popupScript += " ModalDialog.eventhandler =
'YesNoCancelReturnMethod()';"
popupScript += " var Title='Test Pop Up Window'; "
popupScript += " var
args='width=350,height=125,left=325,top=300,toolba r=0,';"
popupScript += "
args+='location=0,status=0,menubar=0,scrollbars=1, resizable=0'; "
popupScript += " if (window.opener && !window.opener.closed)"
popupScript += " window.opener.document.bgColor = ""beige"";"
popupScript += " ModalDialogWindow = window.open('', '', args);"
popupScript += " ModalDialogWindow.document.write('<html>');"
popupScript += " ModalDialogWindow.document.write('<head>'); "
popupScript += " ModalDialogWindow.document.write('<title>' + Title +
'</title>');"
popupScript += " ModalDialogWindow.document.write('<script' + '
language=JavaScript>');"
popupScript += " ModalDialogWindow.document.write('function
CloseForm(Response) ');"
popupScript += " ModalDialogWindow.document.write('{ ');"
popupScript += " ModalDialogWindow.document.write(' alert(""inside
CloseForm""); ');"
popupScript += " ModalDialogWindow.document.write(' if (window.opener
&& !window.opener.closed)alert (""window.opener still valid""); ');"
popupScript += " ModalDialogWindow.document.write('
window.opener.ModalDialog.value = Response; ');"
popupScript += " ModalDialogWindow.document.write(' alert(""after
setting ModalDialog.value and before window.close Response = "" + Response);
');"
popupScript += " ModalDialogWindow.document.write(' alert(""before
window.close window.opener.ModalDialog.value = "" +
window.opener.ModalDialog.value); ');"
popupScript += " ModalDialogWindow.document.write(' window.close();
');"
popupScript += " ModalDialogWindow.document.write('} ');"
popupScript += " ModalDialogWindow.document.write('</script' + '>');
"
popupScript += " ModalDialogWindow.document.write('</head>'); "
popupScript += " ModalDialogWindow.document.write('<body
onblur=""window.focus();"">');"
popupScript += " ModalDialogWindow.document.write(Buttons);"
popupScript += " ModalDialogWindow.document.write('</body>');"
popupScript += " ModalDialogWindow.document.write('</html>'); "
popupScript += " ModalDialogWindow.document.close(); "
popupScript += " ModalDialogWindow.focus(); "
popupScript += " alert(""at setInterval ModalDialogWindow.closed = ""
+ ModalDialogWindow.closed);"
popupScript += " ModalDialogInterval =
window.setInterval(""ModalDialogMaintainFocus()"", 5);"
popupScript += "}"
popupScript += "function YesNoCancel()"
popupScript += "{"
popupScript += " alert(""inside YesNoCancel "");"
popupScript += " var Buttons=''; "
popupScript += " Buttons = '<BUTTON
onclick=""javascript:CloseForm(\'Yes\');"" type=""button"">Yes</BUTTON> ';"
popupScript += " ModalDialogShow('Test Pop Up Window',Buttons);"
popupScript += "}"
popupScript += "function YesNoCancelReturnMethod()"
popupScript += "{"
popupScript += " alert(""inside YesNoCancelReturnMethod"");"
popupScript += " document.getElementById('theTextBox').value = 'Yes';"
popupScript += " ModalDialogRemoveWatch();"
popupScript += "}"
popupScript += "<"
popupScript += "/"
popupScript += "script>"

If(Not IsClientScriptBlockRegistered("PopupScript"))
RegisterClientScriptBlock("PopupScript", popupScript)

end if

End Sub
</script>
</head>
<body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">
<input type="text" id="show" value="a test" style="width=200"
runat="server">
<input type="button" value="ClickMe" onclick="YesNoCancel();">
<asp:Button ID="Button1" text="submit" runat="server"/>
<asp:textbox ID="theTextBox" runat="server"/>
</form>
<input type="text" id="theValue">
</body>
</html>
************************************************** ************************

Thanks,

Tom
Jul 23 '05 #9

P: n/a
tshad wrote:
My problem is that I am trying to set up a popup window that asks the user what they want to do based on something happening on the page. It is not just a "do you really want to delete this" type of question where you can use the standard "confirm" window. The problem with that is you either go on or do nothing. I need to know whether to do one thing or another in my asp page. I need to save the value somewhere and then postback to handle the situation. If I don't use an asp.net control, I am not going to post back.
Do you have to use an ASP.NET control? If so, I really don't see a
solution.

But if all you need to do is submit the form once the user clicks a
button in the dialog, you can use javascript to accomplish this:

In the CloseForm function, add the submit():

window.opener.ModalDialog.value = Response;
window.opener.document.forms[0].submit();
window.close();

this will set the ModalDialog value and then submit (postback) the form

I thought you said that you made a couple of changes and it was working for you?


I misunderstood your post and the changes I made are irrelevant

Jul 23 '05 #10

P: n/a
"Brian Munroe" <br************@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
tshad wrote:
My problem is that I am trying to set up a popup window that asks the user
what they want to do based on something happening on the page. It is

not
just a "do you really want to delete this" type of question where you

can
use the standard "confirm" window. The problem with that is you

either go
on or do nothing. I need to know whether to do one thing or another

in my
asp page. I need to save the value somewhere and then postback to

handle the
situation. If I don't use an asp.net control, I am not going to post

back.


Do you have to use an ASP.NET control? If so, I really don't see a
solution.


I am not sure. I have to think it through.

What I want to do is attach it to one of my buttons if there is a problem,
then execute it. It would go to the popup, get a user response (press one
of the 2 or 3 buttons) and return with the button that was pushed. Normally
this would be some event on the button which would go to a function that
would tell me which button was pushed.

But if all you need to do is submit the form once the user clicks a
button in the dialog, you can use javascript to accomplish this:

In the CloseForm function, add the submit():

window.opener.ModalDialog.value = Response;
window.opener.document.forms[0].submit();
window.close();
But where is the value at this point?

And where do I put it so I can get to it on the postback?

We put it in ModalDialog.value, but won't I lose it when I run the
"window.opener.document.forms[0].submit()"?

Also, which event would the Postback go to?

Thanks,

Tom
this will set the ModalDialog value and then submit (postback) the form

I thought you said that you made a couple of changes and it was

working for
you?


I misunderstood your post and the changes I made are irrelevant

Jul 23 '05 #11

P: n/a
tshad wrote:
window.opener.ModalDialog.value = Response;
window.opener.document.forms[0].submit();
window.close();
But where is the value at this point?


Crap, the value of what the user 'chose' from the dialog will be stored
in the object ModalDialog - which now that I think about it, it might
and probably isn't submitted with the form.

To fix this, in the parent window, you will have to create a hidden
variable to store the user's dialog choice. For example:

(Make sure this is inside the <form></form> tag, btw)

<input type="hidden" name="modalDialogValue" value="" />

Then in the Dialog window function CloseForm(), instead of what I have
above put:

window.opener.document.forms[0].modalDialogValue.value = Response;
window.opener.document.forms[0].submit();
window.close();

That way, when the form is posted, the value gets included with the
form submission. Does that make sense?

And where do I put it so I can get to it on the postback?

See above
Also, which event would the Postback go to?


By default, ASP.NET pages are designed to postback to themselves, and
then you control what happens by using page events (for example, you
would tie an event to an ASP.NET button that on submission, saves the
postback data to a database).

Once a user picks a choice from the dialog and the parent form is
submitted, I am assuming you are processing that choice and directing
the user accordingly?

True ASP.NET development is completely different then ASP, PHP, JSP,
etc. I don't know what experience you have with other web development
languages, but I'd suggest picking up a book on ASP.NET to learn the
basics of the architecture, it will save you a lot of hassle.

-- brian

Jul 23 '05 #12

P: n/a
First of all, Brian, thanks for all the help.
To fix this, in the parent window, you will have to create a hidden
variable to store the user's dialog choice. For example:

(Make sure this is inside the <form></form> tag, btw)

<input type="hidden" name="modalDialogValue" value="" />

I did have to actually set it up this way for asp.net to see it:

<input type="hidden" name="modalDialogValue" value=""
id="ModalDialogValue" runat="Server"/>

You need the ID and runat="Server" for asp.net to see it.

I didn't realize at first that you had changed the access to the variable to
have document.forms[0] on it, so it took a little futzying (technical term)
around until I realized I was missing that. I know you told me it had to be
done, but I missed that difference (brain fade).

It does work now, which you can see on the samples site (I still have all
the alerts in it - but you can see the value in the trace window).

http://www.payrollworkshop.com/samples/ScriptTest.aspx (With all the
alerts)
http://www.payrollworkshop.com/samples/ScriptTest2.aspx (alerts taken out)

Then in the Dialog window function CloseForm(), instead of what I have
above put:

window.opener.document.forms[0].modalDialogValue.value = Response;
window.opener.document.forms[0].submit();
window.close();

That way, when the form is posted, the value gets included with the
form submission. Does that make sense?
Yes it does. I also made a change to add to the "show" variable which also
works.

And where do I put it so I can get to it on the postback?

See above
Also, which event would the Postback go to?


By default, ASP.NET pages are designed to postback to themselves, and
then you control what happens by using page events (for example, you
would tie an event to an ASP.NET button that on submission, saves the
postback data to a database).


I understand how events work (what database does it get saved to BTW?). My
problem was how to get to the event I want on return. It is really evident
in my sample http://www.payrollworkshop.com/samples/ScriptTest2.aspx.

If you look at the page you will see that I have the button set as:

<asp:Button ID="Button1" text="submit" onClick="SomeFunction"
runat="server"/>

So now, when I click the button I should go to the "SomeFunction" function
on Postback.

I also have another function on the button that is put there when the Page
is first opened.

if not IsPostBack then
Button1.Attributes.Add("onclick", "YesNoCancel();")
end if

So now there are 2 functions connected to the button.
1. The asp.net function "SomeFunction"
2. The Javascript function "YesNoCancel()" (although I don't know how
asp.net knows that this is a Javascript function - I don't have
"javascript:" in front of it)

Both events are firing.

The problem is that the postback function is firing first (or at the same
time) as the Javascript function. This is easily seen in the trace window.
When the popup comes up, you can see the page being posted back and the
trace.warn statements in the "SomeFunction" function are in the trace
window - so that event has already fired (which is really too early).

If I were to put a Javascript confirm box on the button, it would get
handled before the asp.net function as shown in the
http://www.payrollworkshop.com/sampl...iptTest3.aspx:

The change would be:

Button1.Attributes.Add("onclick", "return confirm('Are you sure you want
finish this test?');")

Also, if you do the first sample ScriptTest.aspx with the alerts, the
asp.net function first last (but I assume that has to do with the alert
boxes getting in the way).

What I am trying to do is

1. have the popup come up with a couple of buttons.
2. write value to our hidden field that tells me which button was pushed.
3. popup window is closed
4. Postback is done
5. The asp.net function is fired and I handle the buttons. This is
important as it also tells me which asp.net button I am dealing with as I
could have different buttons on the page with the popup on it.

Right now, the function is executed before the user makes a choice.

Once a user picks a choice from the dialog and the parent form is
submitted, I am assuming you are processing that choice and directing
the user accordingly?
Correct, but as I mentioned above, the function that processes that choice
is executed before the Javascript popup is done. In the confirm button, it
doesn't get posted until after the confirm button closes - and if the user
presses the cancel button, it doesn't post back at all).

True ASP.NET development is completely different then ASP, PHP, JSP,
etc. I don't know what experience you have with other web development
languages, but I'd suggest picking up a book on ASP.NET to learn the
basics of the architecture, it will save you a lot of hassle.


Quite a bit if experience, actually. Have been working with asp.net for
about a year. I also worked with another proprietary program that does much
of what asp.net does (but in different ways).

I am doing exactly that. I have many books on it (some I have even read).
:)

The problem is that no how many books you read, you don't get all of it.
Many of the books don't get into the ins and outs of the DataGrid, DataList
or Repeater and how to deal with finding object on the different
datalistitems, for example. They just show you how to use the controls in a
basic way. Scott Mitchell's book on the Data Controls is really good and
explains these controls real well

Here is the page at http://www.payrollworkshop.com/samples/ScriptTest.aspx.

************************************************** ************************************************** *************
<%@ Page Language="VB" trace="true" debug="true" AutoEventWireup="true"
ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<html>
<head>
<script language="VB" runat="server">
Sub Page_Load( sender as Object,e as EventArgs)
trace.warn("show = " & show.value)
trace.warn("modalDialogValue = " & modalDialogValue.value)

if not IsPostBack then
Button1.Attributes.Add("onclick", "YesNoCancel();")
end if

'Form the script that is to be registered at client side.'
Dim scriptString as String = "<script language=JavaScript> function
DoClick() {"
scriptString += "myForm.show.value='Welcome to Microsoft .NET'}<"
scriptString += "/"
scriptString += "script>"

If(Not IsClientScriptBlockRegistered("clientScript"))
RegisterClientScriptBlock("clientScript", scriptString)
End If

Dim popupScript As String = "<script language='javascript'>"
popupScript += "var ModalDialogWindow;"
popupScript += "var ModalDialogInterval;"
popupScript += "var ModalDialog = new Object;"
popupScript += "ModalDialog.value = 'The Value';"
popupScript += "ModalDialog.eventhandler = '';"
popupScript += "function ModalDialogMaintainFocus()"
popupScript += "{"
popupScript += " try"
popupScript += " {"
popupScript += " if (ModalDialogWindow.closed)"
popupScript += " {"
popupScript += " window.clearInterval(ModalDialogInterval);"
popupScript += " eval(ModalDialog.eventhandler);"
popupScript += " return;"
popupScript += " }"
popupScript += " ModalDialogWindow.focus(); "
popupScript += " }"
popupScript += " catch (everything) { alert(everything); }"
popupScript += "}"
popupScript += "function ModalDialogRemoveWatch()"
popupScript += "{"
popupScript += " ModalDialog.value = '';"
popupScript += " ModalDialog.eventhandler = '';"
popupScript += "}"
popupScript += "function ModalDialogShow(Title,Buttons) "
popupScript += "{"
popupScript += " ModalDialogRemoveWatch();"
popupScript += " ModalDialog.eventhandler =
'YesNoCancelReturnMethod()';"
popupScript += " var Title='Test Pop Up Window'; "
popupScript += " var
args='width=350,height=125,left=325,top=300,toolba r=0,';"
popupScript += "
args+='location=0,status=0,menubar=0,scrollbars=1, resizable=0'; "
popupScript += " if (window.opener && !window.opener.closed)"
popupScript += " window.opener.document.bgColor = ""beige"";"
popupScript += " ModalDialogWindow = window.open('', '', args);"
popupScript += " ModalDialogWindow.document.write('<html>');"
popupScript += " ModalDialogWindow.document.write('<head>'); "
popupScript += " ModalDialogWindow.document.write('<title>' + Title +
'</title>');"
popupScript += " ModalDialogWindow.document.write('<script' + '
language=JavaScript>');"
popupScript += " ModalDialogWindow.document.write('function
CloseForm(Response) ');"
popupScript += " ModalDialogWindow.document.write('{ ');"
popupScript += " ModalDialogWindow.document.write('
window.opener.document.forms[0].ModalDialogValue.value = Response; ');"
popupScript += " ModalDialogWindow.document.write('
window.opener.document.forms[0].show.value = Response; ');"
popupScript += " ModalDialogWindow.document.write('
window.opener.document.forms[0].submit();');"
popupScript += " ModalDialogWindow.document.write(' window.close();
');"
popupScript += " ModalDialogWindow.document.write('} ');"
popupScript += " ModalDialogWindow.document.write('</script' + '>');
"
popupScript += " ModalDialogWindow.document.write('</head>'); "
popupScript += " ModalDialogWindow.document.write('<body
onblur=""window.focus();"">');"
popupScript += " ModalDialogWindow.document.write(Buttons);"
popupScript += " ModalDialogWindow.document.write('</body>');"
popupScript += " ModalDialogWindow.document.write('</html>'); "
popupScript += " ModalDialogWindow.document.close(); "
popupScript += " ModalDialogWindow.focus(); "
popupScript += " ModalDialogInterval =
window.setInterval(""ModalDialogMaintainFocus()"", 5);"
popupScript += "}"
popupScript += "function YesNoCancel()"
popupScript += "{"
popupScript += " var Buttons=''; "
popupScript += " Buttons = '<BUTTON
onclick=""javascript:CloseForm(\'Yes\');"" type=""button"">Yes</BUTTON> ';"
popupScript += " ModalDialogShow('Test Pop Up Window',Buttons);"
popupScript += "}"
popupScript += "function YesNoCancelReturnMethod()"
popupScript += "{"
popupScript += " document.getElementById('theTextBox').value = 'Yes';"
popupScript += " ModalDialogRemoveWatch();"
popupScript += "}"
popupScript += "<"
popupScript += "/"
popupScript += "script>"

If(Not IsClientScriptBlockRegistered("PopupScript"))
RegisterClientScriptBlock("PopupScript", popupScript)

end if

End Sub

sub SomeFunction (s as object, e as eventArgs)
trace.warn("am in SomeFunction")
trace.warn("ModalDialogValue = " & ModalDialogValue.value)
end sub
</script>
</head>
<body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">
<input type="text" id="show" name="show" value="a test"
style="width=200" runat="server">
<input type="button" value="ClickMe" onclick="YesNoCancel();">
<asp:Button ID="Button1" text="submit" onClick="SomeFunction"
runat="server"/>
<asp:textbox ID="theTextBox" runat="server"/>
<input type="hidden" name="modalDialogValue" value=""
id="ModalDialogValue" runat="Server"/>
</form>
<input type="text" id="theValue">
</body>
</html>

************************************************** ************************************************** ********************

Thanks,

Tom
Jul 23 '05 #13

P: n/a
"Brian Munroe" <br************@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
Are you getting any Javascript errors? I am trying it in IE 6, Firefox
using ASP.NET and Cassini - it seems to work fine, but I did have to
unwrap some of the JavaScript due to what I am assuming is the fault of
the newsreader.

I've found that the JavaScript console in Firefox is 100x more verbose
then IEs script error dialog, so if you are getting a javascript error,
try looking there.

Also, since the popup window doesn't have a status bar, you may be
getting an error and not even know it.


If you run the sample :

http://www.payrollworkshop.com/samples/ScriptTest.aspx (With all the
alerts)

as you go through the alerts you will get the error:

TypeError: ModalDialogWindow has no properties

This happens in the ModalDialogMaintainFocus function where it says:

popupScript += " alert(""in ModalDialogMaintainFocus"");"
popupScript += " if (ModalDialogWindow.closed)"

You get the alert box and then the error - so it is having a problem with
ModalDialogWindow.closed - I assume.

This does not happen in IE, but in Mozilla and Netscape it does happen.

I don't know about Firefox. I will install it and check it.

Thanks,

Tom
Jul 23 '05 #14

P: n/a
"tshad" <ts**********@ftsolutions.com> wrote in message
news:fl**************@newssvr13.news.prodigy.com.. .
"Brian Munroe" <br************@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
Are you getting any Javascript errors? I am trying it in IE 6, Firefox
using ASP.NET and Cassini - it seems to work fine, but I did have to
unwrap some of the JavaScript due to what I am assuming is the fault of
the newsreader.

I've found that the JavaScript console in Firefox is 100x more verbose
then IEs script error dialog, so if you are getting a javascript error,
try looking there.

Also, since the popup window doesn't have a status bar, you may be
getting an error and not even know it.
If you run the sample :

http://www.payrollworkshop.com/samples/ScriptTest.aspx (With all the
alerts)

as you go through the alerts you will get the error:

TypeError: ModalDialogWindow has no properties

This happens in the ModalDialogMaintainFocus function where it says:

popupScript += " alert(""in ModalDialogMaintainFocus"");"
popupScript += " if (ModalDialogWindow.closed)"

You get the alert box and then the error - so it is having a problem with
ModalDialogWindow.closed - I assume.

This does not happen in IE, but in Mozilla and Netscape it does happen.

I don't know about Firefox. I will install it and check it.


I just checked and it works fine as you said. I also checked Mozilla and it
works (on the version with no alerts), I noticed Firefox has the same
problem with the one with the alerts. IE doesn't have the problem, but it
may have something to do with some of the windows that are opening that go
behind the actual popup window that I can't get access to once the popup
shows up.

I still can't figure out how to get the asp.net event to fire after I come
back from the popup window event (as it does with the confirm box..

It is kind of useless until I figure that one out as I will already have
come back from the asp.net event that is doing the processing the javascript
request, before the Javascript request is done. You can see it pretty
clearly in the http://www.payrollworkshop.com/samples/ScriptTest2.aspx
example. The asp.net event has fired when the Javascript popup window first
comes up.

Tom
Thanks,

Tom

Jul 23 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.