This is a migrated thread and some comments may be shown as answers.

Problem of using javascript in Radgrid item command event

2 Answers 173 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
MSyma
Top achievements
Rank 1
MSyma asked on 25 Jan 2013, 09:45 AM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Jan 2013, 10:33 AM
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
0
Zaid
Top achievements
Rank 1
answered on 02 Feb 2017, 03:25 PM

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);
Tags
General Discussions
Asked by
MSyma
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Zaid
Top achievements
Rank 1
Share this question
or