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

RadGrid's NeedDataSource Firing Another Postback?

16 Answers 591 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
not
Top achievements
Rank 1
not asked on 09 Dec 2010, 09:30 PM
I have a page structure like this:

-- Master Page
    -- Page
        -- User Control
            -- RadGrid

In the user control the component structure is like this:

-- <div>
    -- <ajax:ModalPopupExtender>
        -- <asp:Panel>
            -- <telerik:RadGrid>

In my user control's Page_Load method, I have something like:

protected void Page_Load(object sender, EventArgs e)
{
    LinkButton myLinButton = myMasterTemplate.MyButton; 
    myLinkButton.Click += myLinkButton_Click; 
    
    if (Page.IsPostBack) 
        myGrid.NeedDataSource += myGrid_NeedDataSource 
    
    ...(more code)
}

What happens is when I click on the link button the modal window will show up which contains the grid. It works fine except the user control's Page_Load event fires twice. If I comment out the line "myGrid.NeedDataSource += myGrid_NeedDataSource " then it's fine but of course I can't do that. This leads me to believe, internally, NeedDataSource is causing another postback. Is this correct? If so, is there any way to prevent this from happening?

Thanks.

16 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 10 Dec 2010, 10:32 AM
Hello,

Try attaching the event handler as follows:

protected void Page_Init(object sender, EventArgs e) 
{  
    myGrid.NeedDataSource += new GridNeedDataSourceEventHandler(myGrid_NeedDataSource);      
}

Hope it helps.

Best wishes,
Tsvetoslav
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
not
Top achievements
Rank 1
answered on 09 Mar 2011, 01:33 AM
This doesn't help. Attaching the event the way you suggested still causes a postback. I guess my quesitons are:

1. Does NeedDataSource (which I assume internally it's also calling DataBind()) always fire a postback?
2. If so, is there any way to prevent such behavior?

Thanks.
0
Tsvetoslav
Telerik team
answered on 09 Mar 2011, 03:25 PM
Hi,

RadGrid does not internally make post-backs on any event - therefore the reason lies elsewhere. Please, open a formal support ticket and attach your files for us to investigate the issue. Thanks for that.


Best wishes,
Tsvetoslav
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
improwise
Top achievements
Rank 1
Iron
Iron
answered on 30 Mar 2011, 03:44 PM
We also have the same problem, with DataSource set, the RadGrid calls DataBind(), and with no DataSource set, it calls NeedDataSource twice. We have tested this on a testpage, only containing a RadGrid with almost everything set to default (as it is when you drop a new RadGrid on a page) and an ObjectDataSource, and the RadGrid will still rebind twice. From what I have seen, we seem to be far from the only one with this problem, so please let us know what is causing this and what we can do about it. It really sounds like it could be a bug in the RadGrid?

What we have seen, this only seem to happen if you apply a filter, but NOT if you choose "No filter" as filter option (in case it will only databind once). Also, we have the feeling that this occours much more frequently with AJAX than without.
0
Tsvetoslav
Telerik team
answered on 04 Apr 2011, 04:14 PM
Patrik ,

Make sure that you are using Advanced data-binding and not simple data-binding. If you have done so, please, provide your code. 

Regards,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
improwise
Top achievements
Rank 1
Iron
Iron
answered on 04 Apr 2011, 04:24 PM
Tsvetosla,

I'm confused, I mentioned in the post before you that we experienced the same situation both with DataBind() (simple data binding) and NeedDataSource (Advanced Data Binding), so I don't understand your question? Also, are you saying that the Simple Data Binding is broken and should not be used?

A side note...I seem to remember having read something about having a drop down as a filter could cause multiple selects to fire, but I can't seem to find this info now. Does it ring a bell with anyone?
0
improwise
Top achievements
Rank 1
Iron
Iron
answered on 04 Apr 2011, 05:17 PM
We have done some further testing regarding this and it seems like this might not be a Telerik problem after all.

We are using DotNetNuke as our CMS, which mean that all functionality should be implemented as user controls, which is no problem. However, when using the RadTabStrip/RadMultiPage to build our module navigation, we have implemented this as more user controls, one per PageView. This mean we have nestled user controls, and for some still unknown reason, this seem to trigger multiple Page_Loads to be fired, not only one per user control, but in fact twice per user control. This will of course also fire multiple DataBinds/NeedDataSource in RadGrid. We also tried to add a standard MS GridView to the nestled user control, and it behaved the same, multiple DataBinding events.

I would guess that this could be a problem facing many developers using Telerik/DotNetNuke, of which some perhaps are unaware of this as it won't really show unless you starts looking into performance problems etc. We are currently investigating how to solve this, but if anyone has some great ideas how to work this out, please share.
0
not
Top achievements
Rank 1
answered on 05 Apr 2011, 05:36 AM
After I posted this thread I also found out RadGrid was not at fault, it was our user control's behavior so I'll provide my findings to see if can help.

The RadGrid in our user control has a client event hooked up to a js function which sends a AjaxRequest to simulate a row click when the page is shown so that related detail information will also display. The problem is AjaxRequest is actually a postback so when the following events occur:

1. Control's Page_Load
2. Page's Page_Load
3. Control's AjaxRequest
4. Page's Page_Load

I don't know if your situation is similar but i guess something somewhere must be doing another postback.
0
Tsvetoslav
Telerik team
answered on 07 Apr 2011, 01:08 PM
Hello Patrik,

Still without looking at your code it is difficult to determine what the cause for the trouble might be. What I had in mind by stressing the need to use Advance data-binding is that you should not have calls to the grid's DataBind() method anywhere in the code (only Rebind() should be used when the grid is to be repopulated). It's best if you open up a formal support ticket and send your files as an attachment. 

Regards,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
MTC
Top achievements
Rank 1
answered on 30 Jan 2013, 01:10 PM
No it is not firing in Page init event........
0
MTC
Top achievements
Rank 1
answered on 07 Feb 2013, 12:05 PM
Hi..
I am using RadAjaxManager, Rad Grid and Rad Button and on Rad Button Click i am updating a record after successful update i want to rebind the grid without occurring page post back.. for this what i have to do??
0
Tsvetoslav
Telerik team
answered on 08 Feb 2013, 11:11 AM
Hi Shweta,

You just need to call the grid's Rebind() method in the click event of the rad button. And do make sure that you have ajaxified the grid - the button should ajaxify RadGrid so that asynchronous request is made.


Regards, Tsvetoslav
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
MTC
Top achievements
Rank 1
answered on 12 Feb 2013, 11:34 AM
Hi All..
I am using RadAjaxManager and RadAjaxLoadingPanel with RadGrid. On grid column i have asp linkbutton and on that link button click i am calling one javascript function..
everything is working fine but on that link button click i am not able to show loading panel and also post back occurs :(
below is my code :

 ajax setting is :
 <telerik:AjaxSetting AjaxControlID="lnkbtnDownload">
                                <UpdatedControls>
                                    <telerik:AjaxUpdatedControl ControlID="rg_Attachments" LoadingPanelID="tlkRadAjaxLoadingPnl" />
                                </UpdatedControls>
                            </telerik:AjaxSetting>
On Grid i have asp link button on  GridTemplateColumn like:

  <telerik:GridTemplateColumn HeaderText="Download">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClientClick="return downloadpdf(id);"
                                            ForeColor="Blue"></asp:LinkButton>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>

and this is my javascript function:
 <script language="javascript" type="text/javascript">
        function downloadpdf(id) {
            var annid = id.replace("lnkDownload", "annId");
            window.location = "DownloadAttachment.ashx?id=" + document.getElementById(annid).value;
            return false;
        }
    </script>


Please help........
0
Tsvetoslav
Telerik team
answered on 15 Feb 2013, 12:54 PM
Hi Shweta,

You are effectively making a post back since the javascript calls redirects to an http handler to download a file - that's the reason why the loading panel is not showing. Your scenario is a bit tricky but you can still work around it as demonstrated in the following code library:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/show-loading-panel-when-exporting-radgrid.aspx

The code library is implemented for an export but it is essentially the same set-up as in your case and it should be easy for you to adapt it to your implementation.

Hope it helps.

Regards, Tsvetoslav
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
subbulaxmi
Top achievements
Rank 1
answered on 12 Nov 2015, 09:00 PM

I have a similar issue where I am binding the Radgrid on the click of a button.The NeedDataSource considers even the button click as a postback and is fired twice every time. This happens both for events inside the grid and outside like the button click. How can I avoid this and make sure the button click does not call the needdatasource.

0
Eyup
Telerik team
answered on 17 Nov 2015, 02:29 PM
Hello Subbulaxmi,

Please make sure that you are calling the Rebind() method of the grid only after the click event handler of the button and you don't have genuine DataBind() or Rebind() anywhere else:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/changing-the-grid-structure-dynamically-on-postback

Hope this helps.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Ajax
Asked by
not
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
not
Top achievements
Rank 1
improwise
Top achievements
Rank 1
Iron
Iron
MTC
Top achievements
Rank 1
subbulaxmi
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or