Link to home
Start Free TrialLog in
Avatar of Abdu_Allah
Abdu_Allah

asked on

How to javascript code in a different lines using RegisterStartupScript

Hi; How to javascript code in a different lines using RegisterStartupScript , foexample, consider the following code:
Page.ClientScript.RegisterStartupScript(this.GetType(), "yyh", "<script>alert('1'); alert('2');</script>");

This function will print the code in the web page as the following "<script>alert('1'); alert('2');</script>
How to make it printed like this:

<script>
alert('1');
 alert('2');
</script>
ASKER CERTIFIED SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hehdaddy
hehdaddy

You can also insert line breaks:

"<script>\nalert('1');\nalert('2');\n</script>"
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Abdu_Allah

ASKER

line breal "\n" does not work.
the first one I provided should work.
Still if you want to use \n here it is:
Page.ClientScript.RegisterStartupScript(this.GetType(), "yyh", "<script>\n alert('1');\n alert('2');\n </script>");
Copy+paste this ...it is tested and works.