I'm trying to use AJAX or some kind of client-side callback scripting to make my datagrids refresh without having to do a postback everytime. I'm using a master page, which adds a bit to the complexity of it. However, I've got it working to an extent. I'll post some of the code that I've got to see if someone else can tell me where I might be going wrong.
First, on the master page. I've included the javascript functions here.
At the end of the master page, I'm replacing the timed submit with the refresh code:
That's all the master page handles, since the grids I need to refresh are inside the content panels.
Now on the child page.
I'm using the private variable m_eventArgument to just pass the arguments to the GetCallBackResult function.
Like I said, everything seems to be working, but the grid doesn't ever update. I've tried to reload the entire grid and I've tried to just call DataBind() again, but nothing seems to work. Anything that anyone can do to help would be greatly appreciated. If I didn't include something you would like to know, please tell me.
Thanks
First, on the master page. I've included the javascript functions here.
Code:
function RefreshGrid()
{
currentTime = new Date();
var Command="RefreshGrid";
var context = new Object();
context.CommandName = "RefreshGrid";
window.status = currentTime.getHours() + ":" + currentTime.getMinutes() + ":" + currentTime.getSeconds() + " Refreshing data...";
setTimeout("RefreshGrid();", 10*1000);
<%=m_callbackStr%>
}
function CallBackHandler(result, context)
{
if (context.CommandName == "RefreshGrid")
{
window.status = "Refreshing data...Done";
}
}
At the end of the master page, I'm replacing the timed submit with the refresh code:
Code:
<script language="javascript">
<!--
setTimeout("RefreshGrid();", 10*1000);
//setTimeout("document.forms[0].submit();", 60*1000);
-->
</script>
Now on the child page.
Code:
private m_eventArgument As String
Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
Dim callBack As String = ""
Select Case m_eventArgument
Case "RefreshGrid"
'LoadGrid()
gridTest.DataBind()
callBack = "RefreshGrid"
End Select
Return callBack
End Function
Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
m_eventArgument = eventArgument
Trace.Write(" -- CallbackEvent", "eventArgument: " + eventArgument + ", time: " + Now.ToString)
End Sub
Like I said, everything seems to be working, but the grid doesn't ever update. I've tried to reload the entire grid and I've tried to just call DataBind() again, but nothing seems to work. Anything that anyone can do to help would be greatly appreciated. If I didn't include something you would like to know, please tell me.
Thanks