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

Call Javascript function on itemcommand

7 Answers 529 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cristian
Top achievements
Rank 1
Cristian asked on 30 Jan 2012, 11:44 PM
Hi guys.

Is it possible to call a javascript function in itemcommand event fires?

How can I achieve this?

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 31 Jan 2012, 05:38 AM
Hello,

Try with RegisterStartupScript to call javascript function from server side events.
C#:
protected void radgrid1_ItemCommand(object sender, GridCommandEventArgs e)
   {
       if (e.CommandName == "Delete")
       {
           string openWindowScript = "<script language='javascript'>function f(){SelectItems(); Sys.Application.remove_load(f) ;}; Sys.Application.add_load(f)  ;</script>";
           Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", openWindowScript);      
       }
   }
JS:
<script type="text/javascript">
  function SelectItems()
  {
     // Your code
  }
</script>

Thanks,
Princy.
0
Robert
Top achievements
Rank 1
answered on 25 Oct 2012, 07:26 PM
This doesn't actually work when it's an AJAX call rather than a postback.
0
Princy
Top achievements
Rank 2
answered on 26 Oct 2012, 07:08 AM
Hi,

One suggestion is that you can disable the ajax to invoke the javascript function.
aspx:
<telerik:RadAjaxManager ID="mgrr" runat="server" ClientEvents-OnRequestStart="OnRequestStart">
</telerik:RadAjaxManager>
<telerik:GridTemplateColumn>
    <ItemTemplate>
          <asp:Button ID="Button2" CommandName="Delete" runat="server" Text="Button" />
    </ItemTemplate>
 </telerik:GridTemplateColumn>
JS:
function OnRequestStart(sender, args)
 {
   if (args.get_eventTarget().indexOf("Button2") >= 0)
   args.set_enableAjax(false);
}

Thanks,
Princy.
0
answered on 18 Jul 2013, 07:06 AM
Its working superb..

But i need to send one string as parameter to Java script.

Can you help me..?

Thanks
Rk.MooRthy
0
answered on 24 Jul 2013, 09:23 AM
Yeah Its working fine ! Thanks for your valuable reply..

Thanks
-Rk.MooRthy
0
answered on 24 Jul 2013, 09:37 AM
Hi,
I have created one column as "GridButtonColumn" in one dynamic radgrid, When i click a button in any of the row that "GridButtonColumn" column will be hided soon... Can you anyone help me to solve the problem ..?


Thanks
-Rk.MooRthy
0
Eyup
Telerik team
answered on 29 Jul 2013, 08:04 AM
Hi,

Can you please verify that you are closely following the steps provided in the following article when creating the grid structure dynamically?
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html

Or maybe you want to hide the column on purpose when a button is clicked?

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Cristian
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Robert
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or