I have a gridview inside the update panel, and I have javascript that calls the page method using jquery. I would like the page method to update the gridview based on the parameter that it received from the ajax call.
So far I have the following:
1) in javascript there is a function that calls the page method:
function GetNewDate(thedateitem) {
DateString = (valid json date format that works)
$.ajax({
type: "POST",
url: "./CallHistory.aspx/ResetDate",
contentType: "application/json; charset=utf-8",
data: DateString,
dataType: "json",
success: successFn,
error: errorFn
})
};
2) On the aspx page, I have:
<asp:UpdatePanel ID="MyPanel" runat="server">
<ContentTemplate>
<asp:GridView ID="MyGrid">
3) In the code behind:
public partial class Pages_CallHistory : System.Web.UI.Page
{
List<ViewCallHistoryModel> TheCallHistory;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TheDate = new DateTime(2011, 1, 13);
LoadCallHistory(TheDate);
MyGrid.Datasource = TheCallHistory;
MyGrid.Databind;
}
}
protected void LoadCallHistory(DateTime TheDate)
{
linq query that fills the variable TheCallHistory
}
[WebMethod]
public static void ResetDate(DateTime TheNewDate)
{
var test = new Pages_CallHistory();
var test2 = test.LoadCallHistory(TheNewDate.Date);
test.GridCallHistory.DataSource = test2;
test.GridCallHistory.DataBind();
test.MyPanel.Update();
}
What I would like to do in the page method is 1) call LoadCallHistory with the new date parameter and 2) pass the gridview MyGrid to re-bind to the new data that is in TheCallHistory.
I struggle with this page method; it does not work and i am stuck. How it's done?
source
share