Call Javascript function on itemcommand

8 posts, 0 answers
  1. Cristian
    Cristian  avatar
    46 posts
    Member since:
    May 2011

    Posted 30 Jan 2012 Link to this post

    Hi guys.

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

    How can I achieve this?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 30 Jan 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Robert
    Robert avatar
    8 posts
    Member since:
    Feb 2012

    Posted 25 Oct 2012 Link to this post

    This doesn't actually work when it's an AJAX call rather than a postback.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 Oct 2012 Link to this post

    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.
  6. Rk.MooRthy(DLL Version : 2008.3.1314.35)
    Rk.MooRthy(DLL Version : 2008.3.1314.35) avatar
    21 posts
    Member since:
    Jun 2013

    Posted 18 Jul 2013 Link to this post

    Its working superb..

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

    Can you help me..?

    Thanks
    Rk.MooRthy
  7. Rk.MooRthy(DLL Version : 2008.3.1314.35)
    Rk.MooRthy(DLL Version : 2008.3.1314.35) avatar
    21 posts
    Member since:
    Jun 2013

    Posted 24 Jul 2013 Link to this post

    Yeah Its working fine ! Thanks for your valuable reply..

    Thanks
    -Rk.MooRthy
  8. Rk.MooRthy(DLL Version : 2008.3.1314.35)
    Rk.MooRthy(DLL Version : 2008.3.1314.35) avatar
    21 posts
    Member since:
    Jun 2013

    Posted 24 Jul 2013 Link to this post

    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
  9. Eyup
    Admin
    Eyup avatar
    3007 posts

    Posted 29 Jul 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017