I can't get OnClick to fire for RadChart with MVC

Thread is closed for posting
2 posts, 0 answers
  1. Kelly Hamilton
    Kelly Hamilton avatar
    9 posts
    Member since:
    Nov 2009

    Posted 27 Aug 2012 Link to this post

    Hello, I've been testing out the RadChart from RadControls for ASP.NET AJAX and I can't get teh OnClick event to fire when I use the chart in an MVC application. It works fine for a non MVC application. In the MVC application all other event seem to work fine (Init, Load, DataBound,etc). There are a couple of extra steps to get the chart to work on an MVC view which I have followed. The chart displays fine, and I can add the OnCLick with the designer, but when I click on the chart, there is a post back, but the event handler doesn't execute.
    I'm using version 2012.2.815.40 on Windows 7 64 bit with Visual Studio 2010.

    To Reproduce this, I just made a brand new ASP.NET MVC 2 template application with a test project.
    - I added this to the Webconfig:
    under <system.web>
          <httpHandlers>
            <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
            <add verb="*" path="ChartImage.axd" type="Telerik.Web.UI.ChartHttpHandler" validate="false" />
          </httpHandlers>
    and

     

     <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true"/>
        <handlers accessPolicy="Read, Script">
          <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add name="ChartHandler" path="ChartImage.axd" verb="*" type="Telerik.Web.UI.ChartHttpHandler, Telerik.Web.UI" />
        </handlers>
      </system.webServer>

    I updated the Global.asax.cs as follows:

      public static void RegisterRoutes(RouteCollection routes)
      {
       routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
       routes.IgnoreRoute("{controller}/{resource}.axd/{*pathInfo}"); // This is new
       routes.IgnoreRoute("{controller}/{action}/{resource}.axd/{*pathInfo}"); // This is new

       routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
       );

      }

    Then I added a RadChart to the About view and bound it to an XML data file containing:

    <?xml version="1.0" encoding="utf-8" ?>
    <people>
       <person name="Brown, William" all="20" some="50" few="25" notassessed="5"  />
      <person name="Edwards, Kimberly" all="30" some="45" few="20" notassessed="5"  />
      <person name="Evans, Sarah" all="80" some="10" few="5" notassessed="5"  />
      <person name="King, Elizabeth" all="25" some="35" few="35" notassessed="5"  />
      <person name="White, Mark" all="50" some="20" few="10" notassessed="20"  />

    </people>

    Then I added the click hander and DataBound handler to the chart.

    Then when I run the application and show the About view, The chart shows, but the click handler is not called, but other event handlers are called.

    Any help would be appreciated,Thanks,
    Kelly.



  2. Ves
    Admin
    Ves avatar
    2879 posts

    Posted 30 Aug 2012 Link to this post

    Hi Kelly,

    Postback is not part of the ASP.NET MVC paradigm, so I am afraid RadChart.Click event will not work in MVC. Actually, this is true for Button.Click too. You can find it discussed in different forums e.g. here.


    Best regards,
    Ves
    the Telerik team
    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 their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top