在新标签页中打开链接在ASP.NET [英] Open Link in New Tab in ASP.NET
本文介绍了在新标签页中打开链接在ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用一个按钮在ASP.NET新标签中打开链接。我想下面的,但它不工作:
< ASP:按钮的ID =ReportButton=服务器的CssClass =按钮FONT-SIZE =XX-大前景色=白文本=报告的OnClick =ReportButton_Click的OnClientClick =form1.target ='_空白; />
在code, ReportButton_Click
定义如下:
保护无效SkidPackReportButton_Click(对象发件人,EventArgs的发送)
{
GotoPage记述(LocationSkidPackReportPage);
}
和 GotoPage记述
定义如下:
布尔GotoPage记述(字符串页)
{
尝试
{
的Response.Redirect(页);
返回true;
}
赶上(例外)
{
StatusLabel.Text =有找到页面错误。
返回false;
}
}
解决方案
不要做服务器端的的Response.Redirect
,只是做一个客户端 window.open
。例如。
无效GotoPage记述(字符串页){ ScriptManager.RegisterStartUpScript(此,this.GetType(),NEWPAGE的String.Format(window.open({0});,页),真);}
或者更好的是 - 避免回发完全。您可以指定 clientClick
您喜欢按钮:
ReportButton.OnClientClick =的String.Format(window.open({0});返回false;,LocationSkidPackReportPage);
此方式新页面将在客户端被打开,而不需要返回到服务器
I'm trying to use a Button to open a link in a new tab in ASP.NET. I'm trying the following but it isn't working:
<asp:Button ID="ReportButton" runat="server" CssClass="button" Font-Size="XX-Large" ForeColor="White" Text="Report" OnClick="ReportButton_Click" OnClientClick="form1.target='_blank';" />
In the code, ReportButton_Click
is defined as follows:
protected void SkidPackReportButton_Click(object sender, EventArgs e)
{
GoToPage(LocationSkidPackReportPage);
}
and GoToPage
is defined as follows:
bool GoToPage(string page)
{
try
{
Response.Redirect(page);
return true;
}
catch (Exception)
{
StatusLabel.Text = "There was an error finding the page.";
return false;
}
}
解决方案
Don't do server-side Response.Redirect
, just do a client-side window.open
. E.g.
void GoToPage(string page) {
ScriptManager.RegisterStartUpScript(this, this.GetType(), "newPage", String.Format("window.open({0});", page), True);
}
Or better yet - avoid postback altogether. You can assign clientClick
to your button like:
ReportButton.OnClientClick = String.Format("window.open({0});return false;", LocationSkidPackReportPage);
This way new page will be opened on client without need to go back to the server.
这篇关于在新标签页中打开链接在ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文