EnableAJAX in grid

12 posts, 0 answers
  1. Timyr
    Timyr avatar
    36 posts
    Member since:
    Apr 2011

    Posted 20 Nov 2011 Link to this post

    Hi I have a problem! I use RadGrid and RadAjaxPanel and I want to enable ajax because in Grid I have a button and it is downloading something.
    I have a code like this
    void Download_Click(object sender, EventArgs e)
    {
      if (flag)
       {
        Download();
       }
    else
      {
       Don'tDownload();
      }

    And I have script like this
    <script type="text/javascript"
        function onRequestStart(ajaxManager, eventArgs) 
        { 
            if (eventArgs.get_eventTarget().indexOf("DownloadButton") != -1) 
                eventArgs.set_enableAjax(false); 
        } 
    </script> 
     But this script enabled ajax alway! but i want that it enabledAjax only if it download... How I can do this? Thanks)))
  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 22 Nov 2011 Link to this post

    Hello Timyr,

    I followed your steps in the attached sample however ajax is working properly on my side. All operations perform callback, except the download button which performs regular postback.
    Check it out and let me know if I missed something out and what differs in your case.

    All the best,
    Iana Tsolova
    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. Timyr
    Timyr avatar
    36 posts
    Member since:
    Apr 2011

    Posted 22 Nov 2011 Link to this post

    Lana thanks for reply)) But I want to Enable Ajax only if it download! But in your example Ajax enabled if it download and if it doesn't download... 
  4. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 22 Nov 2011 Link to this post

    Hello Timyr,

    Downloading files require full postback. And is not possible during ajax request.
    However you can try using the approach illustrated here.
    Then in the provided sample change the if statement in the javascript to the opposite.

    Regards,
    Iana Tsolova
    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
  5. Timyr
    Timyr avatar
    36 posts
    Member since:
    Apr 2011

    Posted 23 Nov 2011 Link to this post

    Lana how I understand this sample 
    RadAjaxPanel1.ResponseScripts.Add(String.Format(@"window.location.href = ""{0}"";", "http://yoursite.com/Your_File"));
    demonstrate how download file from site href but I have a Stream... Can I set EnabledAjax = false in server? I try 
    RadAjaxPanel1.EnableAJAX = false; in DownloadClick event but it doesn't work...
    
    
    
  6. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 23 Nov 2011 Link to this post

    Hi Timyr,

    You can not disable ajax once it is in a process. You should disable it client-side, before the request is sent to the server. The best place for this is the OnRequestStart event and more information is available here.

    Best wishes,
    Iana Tsolova
    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
  7. Timyr
    Timyr avatar
    36 posts
    Member since:
    Apr 2011

    Posted 23 Nov 2011 Link to this post

    Thanks Lana for your reply)))Maybe I can a send some parametrs from server by client and then i can use it on OnRequestStart event???)))
  8. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 23 Nov 2011 Link to this post

    Hi Timyr,

    I am not sure I understand the last. Can you elaborate on it and what do you expect to happen with this approach?

    All the best,
    Iana Tsolova
    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
  9. Timyr
    Timyr avatar
    36 posts
    Member since:
    Apr 2011

    Posted 24 Nov 2011 Link to this post

    Look! 
    void Download_Click(object sender, EventArgs e)

    {
      if (flag)
       {
        Download();// in this I need to enableAjax because httprequest need it for download
       }
    else
      {
       Don'tDownload();//but in this i don't want enableAjax because I don't want a postback
      }


    In my sample I EnabledAjax in two cases! Maybe I can send some flag and use it where I enableAjax on client?



  10. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 24 Nov 2011 Link to this post

    Hello Timyr,

    In case you need to disable ajax, you should do it on the client, before the request is sent to the server. So you should perform your checks and set the desired flags client-side.
    If you disable ajax on the server, on Download button click, the next request will be performed as postback but this that already started will finish as regular callback.

    Greetings,
    Iana Tsolova
    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
  11. Timyr
    Timyr avatar
    36 posts
    Member since:
    Apr 2011

    Posted 28 Nov 2011 Link to this post

    My issua is open((( I don't understand how I must EnabledAjax in Download() and don't enabledAjax in  Don'tDownload()!!!???
    If I do it in this script
        function onRequestStart(ajaxManager, eventArgs) 
        { 
            if (eventArgs.get_eventTarget().indexOf("DownloadButton") != -1) 
                eventArgs.set_enableAjax(false); 
        } 

    It enabled  in Download() and in Don'tDownload()... Maybe I can registered onRequestStart event in Download() method?
     And don't registered it in Don'tDownload()????
  12. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 29 Nov 2011 Link to this post

    Hi Timyr,

    You can disable ajax only client-side, in the OnRequestStart event. So definitely when you go to the server and the button click is executed, it is too late to decide if ajax should be enabled or disabled. So you should move your logic for checking if Download() or Don'tDownload() should be executed to the client and based on that disabled ajax or leave it enabled.

    Regards,
    Iana Tsolova
    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
Back to Top