ASP.Net 从 CodeBehind 在浏览器中打开新选项卡 [英] ASP.Net Open New Tab in Browser from CodeBehind
问题描述
我需要从后面的 asp.net 代码提供给我的链接打开浏览器选项卡.通常我会有一个链接和 target="_blank"
,但我需要的链接是动态的,所以我必须具有来自代码背后的 _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屋!