tags:

views:

51

answers:

3

Hello,

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();
  string 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!

+1  A: 

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.

Oded
A: 

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;
}
AGoodDisplayName
Amamzing. it took few seconds. I understood what it is! Thank you much buddies!
Ram
A: 

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.

Ehsan