简体   繁体   English

asp.net 按钮点击新页面

[英]asp.net new page on button click

Trying to display a new page, in a new window when the user clicks on a button.尝试在用户单击按钮时在新的 window 中显示新页面。 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.但是,如果url的内容来自任何用户提供的输入,请确保它是安全的,否则。 you may be opening up yourself to script injection attacks.您可能正在向脚本注入攻击敞开心扉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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