message boxes

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

I'm trying to write some code in my Page_Load where the user can click
OK or Cancel in a message box to decide whether they want to be
redirected or not. If the user clicks OK, then they will be redirected,
if they click Cancel, then they will be sent back to the previous page.

The error that I am getting is 'newline in constant' at the part where I
am creating the sScript string.

Can anybody help with this?

Cheers,

Mike


string sPage = "";
string sScript;

switch (Convert.ToString(Request.QueryString"action"))
{
case "AI":
sPage = activate_invisilink.aspx?serial=" + strSerial);
break;
case "AT":
sPage = activate_targeted.aspx?serial=" + strSerial);
break;
}

sScript = "<script type=\"text/javascript\">";
sScript += "if(confirm('this is the message for the confirm box'))
document.location.href='" + sPage + "';";
sScript += "else document.location.href='lastpage.aspx';";

sScript += "</script>";

Page.RegisterClientScriptBlock("Redirect", sScript);
 
In your code where you construct the string
instead of using a single \, use \\. This should solve the
new line error. in C# \ is an escape character.

I hope this helps.
Kiran
 
This still doesn't work. Can anybody help?

sScript = "<script type=\\"text/javascript\\">";
sScript += "if(confirm('this is the message for the confirm box'))
document.location.href='" + sPage + "';";
sScript += "else document.location.href='default.aspx'";
sScript += "</script>;";


Thanks,

Mike
 
Back
Top