2012-11-09 34 views
0

應用程序是.Net。我想記錄超鏈接上的點擊。很簡單。我將其更改爲鏈接按鈕,現在可以執行所需的服務器端代碼來記錄點擊。問題是:現在我無法啓動鏈接到_blank目標。我想吃我的蛋糕,也有它。服務器端代碼和_blank目標。怎麼做?帶_blank目標的服務器代碼

+1

您可以發佈代碼嗎? –

+0

選中此答案。 http://stackoverflow.com/questions/2637087/link-button-property-to-open-in-new-tab – ryadavilli

+0

protected void LinkBut​​ton1_Click(object sender,EventArgs e) { //您的現有代碼記錄單擊... // ... // ... //生成客戶端代碼以在新窗口中打開鏈接 //(假定您已將URL存儲在字符串變量中 // named targetURL) ClientScript.RegisterStartupScript(this.GetType(), 「openLinkInNewWindow」, 「window.open('」+ targetURL +「','_blank');」,true); –

回答

0

您可以使用:ClientScriptManager.RegisterStartupScript Method (Type, String, String)

例如:

// Define the name and type of the client scripts on the page. 
String csname1 = "PopupScript"; 
Type cstype = this.GetType(); 
// Get a ClientScriptManager reference from the Page class. 
ClientScriptManager cs = Page.ClientScript; 
StringBuilder cstext1 = new StringBuilder(); 
cstext1.Append("<script type=text/javascript>window.open(url, '_blank') </"); 
cstext1.Append("script>"); 
cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());