2010-09-27 195 views
2

我試圖在單擊鏈接按鈕時打開新窗口。單擊鏈接按鈕時在新窗口中打開頁面

<asp:LinkButton ID="lnkpackageinfo" CssClass="linkclass" 
    runat="Server" 
    OnClientClick="lnkpackageinfo_Click()">Compare Packages</asp:LinkButton> 

我想在後面的代碼中給出的目標頁面,因爲在目標頁面中我想使用查詢字符串來隱藏幾個按鈕和鏈接。很明顯,

protected void lnkpackageinfo_Click(object sender, EventArgs e) 
{ 

    long MerchantID = CommonHelper.GetLoggedInMerchant(); 
    string querystringpackageinfo = ApplicationData.URL_MERCHANT_COMPANY_PACKAGE + "?MerchantCompanyPayment"; 
    Response.Redirect(querystringpackageinfo, false); 
} 

這不適合我。我在哪裏做錯了?任何人幫助我!先謝謝你!

回答

2

你能做這樣的事嗎?

<asp:LinkButton ID="lnkpackageinfo" CssClass="linkclass" runat="Server"> Compare Packages</asp:LinkButton> 


protected void Page_Load(object sender, EventArgs e) 
{ 
    lnkpackageinfo.Attributes.Add("onclick", "javascript:window.open('" + GetURL()+ "'); return false;"); 

} 


public string GetURL() 
{ 
    long MerchantID = CommonHelper.GetLoggedInMerchant(); 
    string querystringpackageinfo = ApplicationData.URL_MERCHANT_COMPANY_PACKAGE + "? MerchantCompanyPayment"; 

    return querystringpackageinfo; 
} 
+0

令人驚愕。它花了幾秒鐘。我明白它是什麼!非常感謝你的好友! – Ram 2010-09-28 08:52:06

2

您正嘗試使用客戶端標記(OnClientClick)調用服務器端函數(lnkpackageinfo_Click)。

OnClientClick將嘗試調用您在屬性值中命名的JavaScript函數,該函數不會在那裏,因爲該函數是服務器端(代碼隱藏)函數。

您需要在頁面上編寫JavaScript函數才能讓客戶端打開一個新窗口。

0

那麼你不需要()的一兩件事。 此外,只需使用OnClick=lnkpackageinfo_Click屬性。 然後在該函數中設置一個隱藏的字段值來調用一些javascript來打開一個新窗口。

相關問題