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

EnableAJAX in grid

11 Answers 134 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Timyr
Top achievements
Rank 1
Timyr asked on 20 Nov 2011, 06:33 PM
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)))

11 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 22 Nov 2011, 09:48 AM
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
0
Timyr
Top achievements
Rank 1
answered on 22 Nov 2011, 12:26 PM
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... 
0
Iana Tsolova
Telerik team
answered on 22 Nov 2011, 12:33 PM
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
0
Timyr
Top achievements
Rank 1
answered on 23 Nov 2011, 01:36 PM
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...


0
Iana Tsolova
Telerik team
answered on 23 Nov 2011, 04:32 PM
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
0
Timyr
Top achievements
Rank 1
answered on 23 Nov 2011, 09:42 PM
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???)))
0
Iana Tsolova
Telerik team
answered on 24 Nov 2011, 05:26 AM
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
0
Timyr
Top achievements
Rank 1
answered on 24 Nov 2011, 11:54 AM
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?



0
Iana Tsolova
Telerik team
answered on 24 Nov 2011, 02:32 PM
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
0
Timyr
Top achievements
Rank 1
answered on 28 Nov 2011, 08:18 PM
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()????
0
Iana Tsolova
Telerik team
answered on 29 Nov 2011, 05:16 PM
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
Tags
Ajax
Asked by
Timyr
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Timyr
Top achievements
Rank 1
Share this question
or