开发者

Open page in new window when a link button is clicked

I was trying to open a new window when a link button is clicked.

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

I want the target page to be given in the code behind because in the target page i want to use querystring to hide few buttons and links. It is clear

protected void lnkpackageinfo_Click(object sender, EventArgs e)
{

  long MerchantID = CommonHelper.GetLoggedInMerchant();
  st开发者_如何学Pythonring querystringpackageinfo = ApplicationData.URL_MERCHANT_COMPANY_PACKAGE + "?MerchantCompanyPayment";
  Response.Redirect(querystringpackageinfo, false);
}

This doesnot work for me. Where am i doing wrong? Any someone help me out! thank you in advance!


Can you do something like this?

<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;
}


You are trying to call a server side function (lnkpackageinfo_Click) using client side markup (OnClientClick).

OnClientClick will try to call the JavaScript function you have named in the value of the attribute, which will not be there as the function is a server side (code behind) function.

You need to write a JavaScript function on the page in order for the client to open a new window.


Well you don't need the () for one thing. Also, Just use OnClick=lnkpackageinfo_Click attribute. Then in that function set a hidden field value to call some javascript to open a new window.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜