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

postback after paging

8 Answers 190 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ghadeer
Top achievements
Rank 1
ghadeer asked on 04 Jun 2011, 08:45 PM
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

8 Answers, 1 is accepted

Sort by
0
Russ
Top achievements
Rank 1
answered on 05 Jun 2011, 03:46 AM
Can you post a sample code snippet?
0
ghadeer
Top achievements
Rank 1
answered on 05 Jun 2011, 06:20 AM
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>

 

 

 

0
ghadeer
Top achievements
Rank 1
answered on 05 Jun 2011, 09:09 AM
Please any feedback
0
Russ
Top achievements
Rank 1
answered on 05 Jun 2011, 07:03 PM
I meant could you post your code behind snippet.  The aspx page doesn't tell me what is going on.
0
ghadeer
Top achievements
Rank 1
answered on 06 Jun 2011, 11:14 AM
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
0
Russ
Top achievements
Rank 1
answered on 06 Jun 2011, 01:51 PM
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.
0
ghadeer
Top achievements
Rank 1
answered on 07 Jun 2011, 07:08 AM

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

0
Russ
Top achievements
Rank 1
answered on 07 Jun 2011, 02:40 PM
The NeedDataSource event is required when doing certain things in the grid:

  • 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)
  • After automatic sorting
  • When paging event occurs
  • When Edit command is fired
  • 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
  • When grouping/ungrouping columns - right after the RadGrid.GroupsChanging event is raised.
  • When resorting a group
  • When filtering column values
  • When a call to the Rebind() grid method takes place
  • Prior to any detail table binding
  • In some other custom cases.
  • 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

    Tags
    Grid
    Asked by
    ghadeer
    Top achievements
    Rank 1
    Answers by
    Russ
    Top achievements
    Rank 1
    ghadeer
    Top achievements
    Rank 1
    Share this question
    or