My goal here is to remove some slow-running functions from my sql (which are causing the page/query to time out) and have them asynchronously populate after the main data of the page has loaded and is displayed. I've watched this video
http://asp.net/learn/videos/view.aspx?tabid=63&id=118
How Do I: Implement the AJAX Incremental Page Display Pattern?
and tried to implament something but I get no results and no errors. Meaning the text that is suppose to come back from the web service is not. Here is what I have.
1) I programmatically create a div tag in the column with a unique id and set the RowCreated handler to fire the javascript. I could not put it on the RowDataBound because the step below uses it.
If e.Row.RowState = DataControlRowState.Normal Or e.Row.RowState = DataControlRowState.Selected Then
Dim engineeringDocumentId As String = dataRow.Item("EngineeringDocumentId").ToString
Dim rowClientId As String = e.Row.ClientID
e.Row.Cells(5).Text = "<DIV style=" & Chr(34) & "WIDTH: 150px; HEIGHT: 20px; BACKGROUND-COLOR: palegreen" & Chr(34) & " id=" & Chr(34) & rowClientId & "RevisionStatus" & Chr(34) & "></DIV>"
CType(e.Row.NamingContainer, GridView).Attributes.Add("RowCreated", "return GetRevisionStatus('" & engineeringDocumentId & "', '" & rowClientId & "RevisionStatus');")
End If
2) Here's the javascript with the ScriptManagerProxy
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:ScriptManagerProxy ID="EngineeringDocumentsSM" runat="server">
<services>
<asp:ServiceReference Path="~/EngineeringDocuments/EngineeringDocumentsWebService.asmx" />
</services>
</asp:ScriptManagerProxy>
<script language="javascript" type="text/javascript">
<!--
function GetRevisionStatus(engineeringDocumentId, htmlElementId) {
ret = EngineeringDocumentsWebService.GetRevisionStatus(engineeringDocumentId, htmlElementId, OnGetRevisionStatusComplete(htmlElementId), OnGetRevisionStatusTimeOut, OnGetRevisionStatusError);
}
function OnGetRevisionStatusComplete(htmlElementId, result) {
document.getElementById(htmlElementId).innerHTML = result;
}
function OnGetRevisionStatusTimeOut(results) {
alert("TIMEOUT");
}
function OnGetRevisionStatusError(result) {
alert("ERROR");
}
// -->
</script>
3) Finally here is the web service
<%@ WebService Language="VB" Class="EngineeringDocumentsWebService" %>
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class EngineeringDocumentsWebService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetRevisionStatus(ByVal EngineeringDocumentId As Integer) As String
Return "RevisionStatus"
End Function
End Class
I also want to change the background color of the div depending on the resulting value but thought I would get to that after I get it working.
I was also thinging that isn't this the whole purpose of AJAX controls and couldn't I do this somehow with an update panel?