ASP embedded jscript in asp code won't compile / run

T

TdJ

Hi guys,

I am trying to build a dialog box that does the same as an "alert" but with
out the exclamation mark graphic (which is causing some users to think
something has gone wrong !?

I have included my code, the problem is obviously the fact the jscript 'key
words' are in quotes, I have tried replacing them with single quotes " ' "
and that lets me build but doesn't produce a popup.

Any Suggestions??

thanks

tom

=================

string message = SessionState.State.ExtractMessageForUser();
if (message.Length >0 )
{
// the old alert
//Page.RegisterStartupScript("UserAlert", "<script>alert('" + message +
"');</script>");
string s = null;
// Start JScript for User Alert Box
s += "<script>";
s += " function openCenteredWindow(url, name, height, width, parms)
{";
s += " var left = Math.floor( (screen.width - width) / 2);";
s += " var top = Math.floor( (screen.height - height) / 2);";
s += " var winParms = "top=" + top + ",left=" + left +
",height=" + height + ",width=" + width;";
s += " if (parms) { winParms += "," + parms; }";
s += " var win = window.open(url, name, winParms);";
s += " win.document.write('" + message + "');";
s += " if (parseInt(navigator.appVersion) >= 4) {
win.window.focus(); }";
s += " return win;";
s += " }";
s += " openCenteredWindow("","User Alert", 100, 400);";
s += "</script>";

Page.RegisterStartupScript("UserAlert", s);
}

// call base prerender
base.OnPreRender(e);
====================
 
M

Mike Moore [MSFT]

Hi,

I got it to work with two changes. First, I replaced the double quotes with
single quotes. Then I removed the space from "User Alert" in your call to
openCenteredWindow("","User Alert", 100, 400).

Here is the new code which works on my machine.

string message = "hello";
string s = null;
s += "<script>";
s += " function openCenteredWindow(url, name, height, width, parms){";
s += " var left = Math.floor( (screen.width - width) / 2);";
s += " var top = Math.floor( (screen.height - height) / 2);";
s += " var winParms = 'top=' + top + ',left=' + left + ',height='
+ height + ',width=' + width;";
s += " if (parms) { winParms += ',' + parms; }";
s += " var win = window.open(url, name, winParms);";
s += " win.document.write('" + message + "');";
s += " if (parseInt(navigator.appVersion) >= 4)
{win.window.focus(); }";
s += " return win;";
s += " }";
s += " openCenteredWindow('','No_Spaces', 100, 400);";
s += "</script>";

Page.RegisterStartupScript("UserAlert", s);


Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top