简体   繁体   中英

asp.net new page on button click

Trying to display a new page, in a new window when the user clicks on a button. Trying to test it out with this but no luck so far:

Label1.Text = "<form><input type=button name=print value='Print View' onClick='javascript:window.open('http://mylink','mywindow')'></form>";

I think it might be a formatting issue, but just can't see it. For example this works just fine:

<input type=button name=close value='Close' onClick='javascript:parent.jQuery.fancybox.close()'>

Please try:

Label1.Text = "<form><input type=button name=print value='Print View' onClick='javascript:window.open(\"http://mylink\",\"mywindow\")'></form>";

You should probably use:

Label1.Text = @"<form><input type=""button"" name=""print"" value=""Print View"" onClick=""javascript:window.open('http://mylink','mywindow')""></form>";

If you want to include a variable, you can use:

   string url = "http://www.google.com";
   Label1.Text = String.Format(@"<form><input type=""button"" name=""print"" value=""Print View"" onClick=""javascript:window.open('{0}','mywindow')""></form>", url);

However , make sure the contents of url is safe if it came from any user-provided input, Otherwise. you may be opening up yourself to script injection attacks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM