postback after paging

9 posts, 0 answers
  1. ghadeer
    ghadeer avatar
    57 posts
    Member since:
    Mar 2008

    Posted 04 Jun 2011 Link to this post

    Hi there,
    i have textbox with search button to filter radgrid ,I get the filtered data without problem but when I click on next page in the grid
    the grid postback , so the filtered data is missed ,so I get the whole data again
    could you help me who can I solve this issue
    thanks in advance
    ghadeer
  2. Russ
    Russ avatar
    49 posts
    Member since:
    Sep 2006

    Posted 04 Jun 2011 Link to this post

    Can you post a sample code snippet?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. ghadeer
    ghadeer avatar
    57 posts
    Member since:
    Mar 2008

    Posted 05 Jun 2011 Link to this post

    Ok,this is my aspx page

     

     

    <table class="style1"> 

     

     <

    tr>

     

     

    <td colspan="2">

     

     

    <table class="style1">

     

     

    <tr>

     

     <

    td class="style2">

     

     

    <asp:Label ID="Label1" runat="server"Text="Search Option:"></asp:Label</td>

     

     

    <td align="left">

     

     <

    asp:RadioButtonList ID="rblSearchs" runat="server" RepeatDirection="Horizontal">

     

     

    <asp:ListItem Selected="True" Value="0">Referal ID</asp:ListItem>

     

     

    <asp:ListItem Value="1">Hospital ID</asp:ListItem>

     

     

    <asp:ListItem Value="2">Area ID</asp:ListItem>

     

     

    </asp:RadioButtonList>

     

     

    </td> </tr>
    <tr> <td class="style2">

     

     

    <asp:Label ID="Label2" runat="server" Text="Search Text:"></asp:Label>

     

     

    </td

     

    <td>

     

    <asp:TextBox ID="txtSearch" runat="server" Width="262px"></asp:TextBox>

     

     <

     

     

    asp:Button ID="btnSearch" runat="server" Text="Find" CssClass="btn" onclick="btnSearch_Click"/>

     

     

    <asp:Button ID="btnSearchAll" runat="server" Text="Show All" />

     

     

    </td> </tr>

     

     </

    table>

     

     <

    /td</tr>

     

     

    <tr>

     

     

    <td colspan="2">

     

     <

    telerik:RadGrid ID="rGridReferalDetails" runat="server" AllowPaging="True" AutoGenerateColumns="False" GridLines="None" onneeddatasource="rGridReferalDetails_NeedDataSource" Skin="Office2007"

     

     

     

    onprerender="rGridReferalDetails_PreRender" >

     

     

    <ClientSettings>

     

     

    <Selecting AllowRowSelect="True" />

     

     

    <Selecting AllowRowSelect="True"/>

     

     

    </ClientSettings>

     

     

    <MasterTableView>

     

     

    <RowIndicatorColumn Visible="False">

     

     

    <HeaderStyle Width="20px" />

     

     

    </RowIndicatorColumn>

     

     

    <ExpandCollapseColumn Resizable="False" Visible="False">

     

     

    <HeaderStyle Width="20px" />

     

     

    </ExpandCollapseColumn>

     

     

    <Columns>

     

    <telerik:GridBoundColumn DataField="RID" HeaderText="Referal ID" UniqueName="RID" >

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="hospital_name" HeaderText="Hospital Name" UniqueName="hospital_name" AllowFiltering="False">

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="area_name" HeaderText="Area Name" UniqueName="area_name"AllowFiltering="False"> </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="note" HeaderText="Transaction" 

     

     

     

     

    UniqueName="note" AllowFiltering="False"> </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="Rejectreason_name" 

     

     

     

    HeaderText="Rejectreason_name" UniqueName="Reject Reason" AllowFiltering="False"> </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="Createdby" HeaderText="User"UniqueName="Createdby" AllowFiltering

    ="False">

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="createddate" HeaderText="Date"

     

     

     

     

    UniqueName="createddate" AllowFiltering="False"> </telerik:GridBoundColumn>

     

     <

    /Columns>

     

     

    <EditFormSettings>

     

     

    <PopUpSettings ScrollBars="None" />

     

     

    <PopUpSettings ScrollBars="None" />

     

     

    </EditFormSettings>

     

     

    </MasterTableView>

     

     <

    /telerik:RadGrid></td> </tr> <tr><td align="left">  

     

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

     <

    AjaxSettings 

     

    <telerik:AjaxSetting AjaxControlID="btnSearch">

     

    <UpdatedControls>

     

     

    <telerik:AjaxUpdatedControl ControlID="rGridReferalDetails"/>

     

     

    </UpdatedControls>

     

     

    </telerik:AjaxSetting>

     

     

    </AjaxSettings> 

     

     

     

    </telerik:RadAjaxManager>

     

    </td>

     

     

    <td align="left">

     

     

    <asp:HiddenField ID="hdDisplayMode" runat="server"/>

     

     </td>

     

     

    </tr>

     

     

    </table>

     

     

     

  5. ghadeer
    ghadeer avatar
    57 posts
    Member since:
    Mar 2008

    Posted 05 Jun 2011 Link to this post

    Please any feedback
  6. Russ
    Russ avatar
    49 posts
    Member since:
    Sep 2006

    Posted 05 Jun 2011 Link to this post

    I meant could you post your code behind snippet.  The aspx page doesn't tell me what is going on.
  7. ghadeer
    ghadeer avatar
    57 posts
    Member since:
    Mar 2008

    Posted 06 Jun 2011 Link to this post

    Hi,
    Sorry I didnt get you.
    this is the code behind page:

     

     

    protected void Page_Load(object sender, EventArgs e)

     

     

    {

     

    _controller =

     

    new Controller.Referal(this);

     

     

     

     

    if (!IsPostBack)

     

     

    {

     

     

     

    try

     

    {

    DisplayMode =

     

    "ALL";

     

     

    _controller.GetReferal();

     

    }

     

     

     

    catch (Exception)

     

     

    {

     

    }

     

     

     

     

     

    finally

     

    {

    }

    }

     

    }



    #region

     

     

    button click event

     

     

     

     

    protected void btnSearch_Click(object sender, EventArgs e)

     

     

    {

     

     

     

    try

     

    {

     

    DisplayMode =

     

    "Search";

     

     

    rGridReferalDetails.CurrentPageIndex = 0;

     

    _controller.GetReferal();

     

     

     

    }

     

     

     

    catch

     

    {

    }

    }

    #endregion

    protected

     

     

    void rGridReferalDetails_PageIndexChanged(object source, GridPageChangedEventArgs e)

     

     

    {

     

     

     

    }



    I see when I click next page in the grid postback takeplace!!!!
    thanks in advance
  8. Russ
    Russ avatar
    49 posts
    Member since:
    Sep 2006

    Posted 06 Jun 2011 Link to this post

    Looks like you have a NeedDataSource Event and OnPreRender event for the grid registered but I don't see that in your code.  Is this all of your code or did you forget to post something? I'm assuming that Controller.Referal is your data class.  If so in your Page_Load you have the following defined:

    _controller = new Controller.Referal(this); 

    You are getting a new instance of the controller every time you load the page and on the secoond postback (pageindexchanged) your dataset is changing.  Your are not passing the correct parameters to your data access class.  If you can post a sample project that would be better.
  9. ghadeer
    ghadeer avatar
    57 posts
    Member since:
    Mar 2008

    Posted 07 Jun 2011 Link to this post

    Hi ,
    thank you....
    controller is my business class also this :
    _controller =

     

    new Controller.Referal(this);
    is already defined in the page load, regarding needdatasource event I had used it before but I changed
    during my attemp to solve the problem,
    I will copy the page again:

     

     

    public

     

     

    partial class ReferalDetails : System.Web.UI.Page, IReferal

     

     

     

     

     

     

     

     

     

    {

     

     

     

     

     

     

     

    #region

     

     

     

    fields

     

     

     

     

     

    private Controller.Referal _controller = null;

     

     

     

     

     

     

     

     

    #endregion

     

     

     

     

     

     

     

     

     

     

     

    protected void Page_Load(object sender, EventArgs e)

     

     

    {

     

    _controller =

     

     

    new Controller.Referal(this);

     

     

     

     

     

    if (!IsPostBack)

     

     

    {

     

     

     

     

    try

     

     

     

     

     

     

     

     

     

    {

     

    DisplayMode =

     

     

    "ALL";

     

     

    _controller.GetReferal();

     

    }

     

     

     

     

    catch (Exception)

     

     

    {

     

    }

     

     

     

     

     

     

    finally

     

     

     

     

     

     

     

     

     

    {

     

    }

     

    }

     

     

     

    }

     

     

     

     

     

     

     

     

     

    #region

     

     

     

    interface IReferal implementation

     

     

     

     

     

    public int Filter

     

     

    {

     

     

     

     

    get { return Convert.ToInt32(rblSearchs.SelectedItem.Value); }

     

     

    }

     

     

     

     

    public int FilterText

     

     

    {

     

     

     

     

     

     

    get { return Convert.ToInt32(txtSearch.Text); }

     

     

    }

     

     

     

     

     

     

     

     

    public void Clear()

     

     

    {

     

    txtSearch.Text =

     

     

    string.Empty;

     

     

    }

     

     

     

     

    public String DisplayMode

     

     

    {

     

     

     

     

    get

     

     

     

     

     

     

     

     

     

    {

     

     

     

     

     

     

    return Session[" DisplayMode"].ToString();

     

     

     

     

    }

     

     

     

     

     

     

    set { Session[" DisplayMode"] = value.ToString(); }

     

     

    }

     

     

     

     

     

     

    public void MessageAlert(string Text)

     

     

    {

     

     

     

     

    ScriptManager.RegisterStartupScript(Page, typeof(Page), "RegisterScript", "window.alert('" + Text + "')", true);

     

     

    }

     

     

     

     

     

     

    public IListSource ReferalList

     

     

    {

     

     

     

     

    set

     

     

     

     

     

     

     

     

     

    {

     

    rGridReferalDetails.DataSource =

     

     

    value;

     

     

    rGridReferalDetails.DataBind();

     

     

     

    }

     

    }

     

     

     

     

     

     

     

    #endregion

     

     

     

     

     

     

     

     

    #region

     

     

     

    button click event

     

     

     

     

     

    protected void btnSearch_Click(object sender, EventArgs e)

     

     

    {

     

     

     

     

    try

     

     

     

     

     

     

     

     

     

    {

     

     

     

    DisplayMode =

     

     

    "Search";

     

     

    rGridReferalDetails.CurrentPageIndex = 0;

     

    _controller.GetReferal();

     

     

     

    }

     

     

     

     

    catch

     

     

     

     

     

     

     

     

     

    {

     

    }

     

    }

     

     

     

     

     

     

     

    #endregion

     

     

     

     

     

     

     

     

     

     

     

     

     

    protected void btnSearchAll_Click(object sender, EventArgs e)

     

     

    {

     

     

     

     

    try

     

     

     

     

     

     

     

     

     

    {

     

    Clear();

     

    DisplayMode =

     

     

    "ALL";

     

     

    rGridReferalDetails.CurrentPageIndex = 0;

     

    _controller.GetReferal();

     

    }

     

     

     

     

    catch

     

     

     

     

     

     

     

     

     

    {

     

    }

     

    }

     

     

     

     

     

     

     

     

    protected void rGridReferalDetails_PageIndexChanged(object source, GridPageChangedEventArgs e)

     

     

    {

     

     

     

     

     

    }

     

    }


    I think you get exactly what is my problem,every time I click on next page,,page postback and filtered data is lost.

    thanks in advance

  10. Russ
    Russ avatar
    49 posts
    Member since:
    Sep 2006

    Posted 07 Jun 2011 Link to this post

    The NeedDataSource event is required when doing certain things in the grid:

  11. Right after OnLoad, Telerik RadGrid checks the viewstate for stored grid-related information. If such information is missing (when the page loads for the first time), the NeedDataSource event is fired. This also means that if the EnableViewState property of the grid has been set to false, the grid will bind each time the page loads (not only the first time)
  12. After automatic sorting
  13. When paging event occurs
  14. When Edit command is fired
  15. Right after Update/Delete/Insert command event handlers finish execution. You can cancel these operations handling the ItemCommand event and assigning false value to the Canceled property of the e event argument
  16. When grouping/ungrouping columns - right after the RadGrid.GroupsChanging event is raised.
  17. When resorting a group
  18. When filtering column values
  19. When a call to the Rebind() grid method takes place
  20. Prior to any detail table binding
  21. In some other custom cases.
  22. I would check the following demo to ensure you have what you need.

    http://demos.telerik.com/aspnet-ajax/grid/examples/programming/needdatasource/defaultcs.aspx

  • Back to Top
    UI for ASP.NET Ajax is Ready for VS 2017