RadGrid's NeedDataSource Firing Another Postback?

17 posts, 0 answers
  1. not
    not avatar
    8 posts
    Member since:
    Dec 2010

    Posted 09 Dec 2010 Link to this post

    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.

  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 10 Dec 2010 Link to this post

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

    Posted 08 Mar 2011 Link to this post

    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.
  5. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 09 Mar 2011 Link to this post

    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!
  6. Patrik Johansson
    Patrik Johansson avatar
    270 posts
    Member since:
    May 2010

    Posted 30 Mar 2011 Link to this post

    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.
  7. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 04 Apr 2011 Link to this post

    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
  8. Patrik Johansson
    Patrik Johansson avatar
    270 posts
    Member since:
    May 2010

    Posted 04 Apr 2011 Link to this post

    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?
  9. Patrik Johansson
    Patrik Johansson avatar
    270 posts
    Member since:
    May 2010

    Posted 04 Apr 2011 Link to this post

    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.
  10. not
    not avatar
    8 posts
    Member since:
    Dec 2010

    Posted 05 Apr 2011 Link to this post

    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.
  11. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 07 Apr 2011 Link to this post

    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
  12. MTC
    MTC avatar
    26 posts
    Member since:
    Jan 2013

    Posted 30 Jan 2013 Link to this post

    No it is not firing in Page init event........
  13. MTC
    MTC avatar
    26 posts
    Member since:
    Jan 2013

    Posted 07 Feb 2013 Link to this post

    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??
  14. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 08 Feb 2013 Link to this post

    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.
  15. MTC
    MTC avatar
    26 posts
    Member since:
    Jan 2013

    Posted 12 Feb 2013 Link to this post

    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........
  16. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 15 Feb 2013 Link to this post

    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.
  17. subbulaxmi
    subbulaxmi avatar
    4 posts
    Member since:
    Oct 2015

    Posted 12 Nov 2015 Link to this post

    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.

  18. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 17 Nov 2015 Link to this post

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