Problem of using javascript in Radgrid item command event

3 posts, 0 answers
  1. MSyma
    MSyma avatar
    6 posts
    Member since:
    Oct 2012

    Posted 25 Jan 2013 Link to this post

    Hello,

    I' m facing the problem that is window.open() javascript funtion for open new tab doen't work in Radgrid item command event.Here is my Code for Item Command.

     protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
     {
                  if (e.CommandName == "Customer")
                    {
                        lblID.Text = RadGrid2.Items[e.Item.ItemIndex].GetDataKeyValue("ID").ToString();
                        string strpath=  "../Report/Listing.aspx?ID=" + lblID.Text + "";
                      
                        Response.Write("<script>");
                        Response.Write("window.open('" + strpath + "', '_newtab');");
                        Response.Write("window.focus();");
                        Response.Write("</script>");
                    }
    }
    I do appreciate all suggestions.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Jan 2013 Link to this post

    Hi,

    I suppose you want to open a new tab in button click. Here is the sample code.
    C#:
    protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
      if (e.CommandName == "open")
      {
        GridDataItem item = (GridDataItem)e.Item;
        Button btn = (Button)item.FindControl("Button2");
        btn.Attributes.Add("onclick", "open");
      }
    }
    JS:
    function open()
    {
      window.open(url, '_newtab');
    }

    Thanks,
    Shinu
  3. Zaid
    Zaid avatar
    1 posts
    Member since:
    Oct 2014

    Posted 02 Feb Link to this post

    Hello..I'm having the similar problem,

    I have LinkButton inside RadGrid, on ItemCommand event handler i want to call a javascript function,please note that when i click on the LinkButton notheing happens but it works after that..please help

    below is sample of my code:

    telerik:GridTemplateColumn UniqueName="TemplateAddColumn">
           <ItemTemplate>
                 <asp:LinkButton ID="lnkAdd" runat="server" Text="Add" Visible="false" CommandName="Add"></asp:LinkButton>
           </ItemTemplate>
    </telerik:GridTemplateColumn>
    LinkButton editLink = (LinkButton)e.Item.FindControl("lnkAdd");
    editLink.Attributes["href"] = "javascript:void(0);";
    editLink.Attributes["onclick"] = String.Format("return JSFunction('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["IndividualsID"], e.Item.ItemIndex);
Back to Top