ASP.Net从CodeBehind在浏览器中打开新选项卡 [英] ASP.Net Open New Tab in Browser from CodeBehind
问题描述
我需要从后面的asp.net代码给我的链接打开浏览器选项卡。
通常我会有一个链接和 target =_ blank
,但我需要的链接是动态的,所以我必须有一个<$ c的行为$ c> _blank 后面的代码链接。
I need to open a browser tab from a link that is given to me by an asp.net code behind.
Normally I would have a link and target="_blank"
, but the link that I need is dynamic, so I must have the behavior of a _blank
link from code behind.
任何想法?
推荐答案
如果您在生成初始HTML时拥有创建链接所需的数据,您可以在Page_Load事件中执行以下操作:
If you have the data needed to create the link when generating the initial HTML, you can do something like this in the Page_Load event:
protected void Page_Load(object sender, EventArgs e)
{
Button1.OnClientClick="javascript:window.open('MyPage.aspx?Param=" + Param1.ToString() + "');"; }
}
如果您正在等待PostBack获取所需的数据来构建链接,您可以通过ScriptManager将javascript发送到浏览器:
If you're waiting for the PostBack to get the required data to build the link, you can send javascript down to the browser via the ScriptManager:
protected void Button1_Click(object sender, EventArgs e)
{
//process whatever you need to to get Param1
ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('MyPage.aspx?Param=" + Param1.ToString() + "');",true);
}
这篇关于ASP.Net从CodeBehind在浏览器中打开新选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!