Second postback breaks RadGrid

7 posts, 0 answers
  1. Andrew Watt
    Andrew Watt avatar
    6 posts
    Member since:
    Oct 2009

    Posted 26 Nov 2009 Link to this post

    Hey people...

    I have an issue with a user control I have created which is meant to provide search results through the use of a radgrid.

    I have pasted the code below. As you will see, I have a button which causes a post back and a radgrid (bound to an objectdatasource) to show the results. The grid is configured to enable sorting and paging. There are other controls on the user control(e.g. comboxboxes and textboxes) which are the fields used to provide search criteria.

    The problem I am having is that the page and grid loads fine with initial search results- all events are fired and the expected result is shown, then if I do a search/sort/page change it still works fine but the second and all subsequent postbacks (search/sort/page change)  raise all the events but the results aren't being shown in the browser. I also don't see any exceptions being raised- the databinding seems to run correctly. All the parameters passed to the search method are correct.

    If I remove the radajaxpanel around it all, it works fine (but with all the full page refreshes). I have tried to use RadAjaxManager/proxy and still get the exact same result. Also tried manual binding and still no luck.

    <telerik:RadAjaxPanel ID="ajaxpnlSearch" runat="server"
                <div class="form-row"
                    <div class="float-left" style="width: 100%;"
                        <asp:Button Text="Search" class="search" runat="server" ID="btnSearch" OnClick="btnSearch_Click" /> 
                    </div> 
                    <div class="clear no-text"
                    </div> 
                </div> 
                <div class="clear no-text"
                </div> 
                <telerik:RadGrid ID="grdSearchResults" runat="server" Width="100%" AllowPaging="True" 
                    AllowSorting="True" DataSourceID="odsOpportunities" GridLines="None"
                    <MasterTableView AutoGenerateColumns="False" DataSourceID="odsOpportunities" DataKeyNames="OppId" 
                        EnableViewState="true"
                        <Columns> 
                            <telerik:GridBoundColumn DataField="OppId" HeaderText="OppId" SortExpression="OppId" 
                                UniqueName="OppId" DataType="System.Int64"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="BusinessName" HeaderText="BusinessName" ReadOnly="True" 
                                SortExpression="BusinessName" UniqueName="BusinessName"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" 
                                UniqueName="ContactName" ReadOnly="True"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="OppExpireDate" DataType="System.DateTime" HeaderText="OppExpireDate" 
                                SortExpression="OppExpireDate" UniqueName="OppExpireDate"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="CreatedDate" DataType="System.DateTime" HeaderText="CreatedDate" 
                                SortExpression="CreatedDate" UniqueName="CreatedDate"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="CreatedBy" DataType="System.Int32" HeaderText="CreatedBy" 
                                SortExpression="CreatedBy" UniqueName="CreatedBy"
                            </telerik:GridBoundColumn> 
                        </Columns> 
                    </MasterTableView> 
                    <ClientSettings> 
                        <Selecting AllowRowSelect="True" /> 
                    </ClientSettings> 
                </telerik:RadGrid> 
                <asp:ObjectDataSource ID="odsOpportunities" runat="server" OldValuesParameterFormatString="original_{0}" 
                    SelectMethod="Search" TypeName="Hub.BLL.Opportunity.Opportunity"
                    <SelectParameters> 
                        <asp:ControlParameter ControlID="txtOppId" Name="inOppId" PropertyName="Text" Type="Int32" /> 
                        <asp:ControlParameter ControlID="cmbPartner" Name="inPartnerId" PropertyName="SelectedValue" 
                            Type="Int32" /> 
                        <asp:ControlParameter ControlID="cmbOppStatus" Name="inStatus" PropertyName="SelectedValue" 
                            Type="Int32" /> 
                        <asp:ControlParameter ControlID="cmbOppType" Name="inOppType" PropertyName="SelectedValue" 
                            Type="Int32" /> 
                        <asp:ControlParameter ControlID="dpWOOStartDate" Name="inStartDate" PropertyName="SelectedDate" 
                            Type="DateTime" /> 
                        <asp:ControlParameter ControlID="dpWOOEndDate" Name="inEndDate" PropertyName="SelectedDate" 
                            Type="DateTime" /> 
                        <asp:ControlParameter ControlID="cmbChannel" Name="inChannel" PropertyName="SelectedValue" 
                            Type="Int32" /> 
                        <asp:ControlParameter ControlID="cmbCampaign" Name="inCampaign" PropertyName="SelectedValue" 
                            Type="Int32" /> 
                        <asp:ControlParameter ControlID="cbNew" Name="inNew" PropertyName="Checked" Type="Boolean" /> 
                    </SelectParameters> 
                </asp:ObjectDataSource> 
                <br /> 
            </telerik:RadAjaxPanel> 


            protected void Page_Load(object sender, EventArgs e) 
            { 
                 
            } 
     
            protected void btnSearch_Click(object sender, EventArgs e) 
            { 
                grdSearchResults.DataBind(); 
            } 

    Any help would be appreciated!!!

    Regards,
    Andrew
  2. Andrew Watt
    Andrew Watt avatar
    6 posts
    Member since:
    Oct 2009

    Posted 27 Nov 2009 Link to this post

    Okay I have managed to find the problem here but have no idea why this occurs and maybe someone can give some indication of what is going on.

    The problem has something to do with the depth (in terms of folder structure) of the form hosting the controls.

    Here is what I have:
    Solution.sln (SolutionName)
    Project.csproj (Web) //this is a web application
    MasterPage.Master
    Folder (UserControls)
    Folder(Search)
    // a few .ascx files
    opportunity-search.ascx
    Folder (Webforms)
    Folder(Opportunity)
    // a few .aspx files 
    frmOpportunityAllocate.aspx

    frmOpportunityAllocate.aspx hosts the usercontrol opportunity-search.ascx (which contains the ajaxed radgrid) for some of its functionality.

    Here is where things get weird. In the structure described above, the ajaxed rad grid throws the wobbly I have described in my previous page. If I move the frmOpportunityAllocate.aspx page into the folder "above it" (Webforms), the issue described in my previous post does not occur.

    the page frmOpportunityAllocate.aspx uses materpage Main.master and is hosted in an iframe- but this shouldnt make much of a difference.

    If any more detail is required- please let me know.

    Regards,
    Andrew
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 01 Dec 2009 Link to this post

    Hi Andrew,

    I noticed in the code, that you are calling DataBind() for the grid directly.
    Please, keep in mind, that this is not a recommended approach. You can use the NeedDataSource event handler to pass data to the control, as shown in the following article:

    http://www.telerik.com/help/aspnet-ajax/grdadvanceddatabinding.html

    Calling databind directly at any other stage of the page lifecycle will break the default functionalities of the control. If you need, at any point, to raise the NeedDataSource event handler, you can simply call the .Rebind() method of the control.
    I hope these suggestions get you started properly.

    Kind regards,
    Yavor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Andrew Watt
    Andrew Watt avatar
    6 posts
    Member since:
    Oct 2009

    Posted 01 Dec 2009 Link to this post

    Thanks for pointing that out and I will be sure to make the change and keep it in mind for future development in order to avoid possible issues.

    I still have the problem that I have described above and it is occurring in more than one place.

    Has anyone experienced this sort of folder structure issue?
  6. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 03 Dec 2009 Link to this post

    Hi Andrew,

    For the other issue which you described, it is hard to judge by simply looking at the code snippet(s). If the problem persists at your end, you can open a formal support ticket, and send us the problematic code, in the form of a small working project, for further investigation.

    Kind regards,
    Yavor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Joe
    Joe avatar
    2 posts
    Member since:
    Jul 2013

    Posted 03 Jul 2013 Link to this post

    I have the exact same issue, has this ever been resolved?

    And like Andrew, I use the OnNeedDatasource event and its still causing issues on the second postback.
  8. Joe
    Joe avatar
    2 posts
    Member since:
    Jul 2013

    Posted 03 Jul 2013 Link to this post

    To provide others with more details, folder structure is not causing the issue, not for me anyway and I am using the Q1 2013 dll's.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017