July 10, 2008

"Data Could Not Be Loaded" Issue in ComponentArt Web.UI 2008.1 for ASP.NET 2.0

I am using Component art Web UI tools in a website and was facing a problem from a long time.
Component Art grid and other control throw "Data Could Not Be Loaded" alert in callbacks. After some research I found that this comes when control is not able to get back the data from server during a call back. There can be many reasons for this for example session expire and error during execution of code etc.
Now for component this is not a bug in the product, this is some kind of execption situation which programmer should handle at their end while working with controls.

So I was left with nothing but find out a solution myself, now in my case the message box came up if window was left idle for long time, so it was quite clear that this is a session expire problem.
Drilling down more into the problem I found that main cause was redirection to default page in case session expired.

Solution to the problem is avoiding redirection on server side during callbacks instead use javascript to move to other page. So where ever you have written the code of redirection, try to get status whether it was a postback or a callback and if it was callback don't redirect. Now raise a custom execption like Session Expired during call backs and handle it in callbackerror event exposed by component art control.

Server Side code -
'''Procedure raises custom execption in case of session out

Public Sub RaiseErrorOnSessionTimeOut()
If Me.Session("UserLoggedIn") Is Nothing OrElse Not CBool(Me.Session("UserLoggedIn")) Then
Throw New Exception("Session TimeOut")
End If
End Sub

'''deliberatly raising execption while rebinding component art grid
Public Sub OnNeedRebind(ByVal sender As Object, ByVal oArgs As EventArgs) Handles Grid1.NeedRebind
RaiseErrorOnSessionTimeOut()
Grid1.DataBind()
End Sub

Client Side Code -

//JavaScript Function
///
///Function handles error generated by qualified and dis-qualified result grids
///
function HandleCallBackError(sender, eventArgs)
{
var errorMessage = new String();
errorMessage = eventArgs.get_errorMessage().toLowerCase();

switch (errorMessage)
{
case "session timeout":
window.location.replace("samepage.aspx")
break;
default:
alert("Due to some technical problem we are unable to process your request.");
break;
}

}


Add a client event to the grid.
<ClientEvents>
<CallbackError EventHandler="HandleCallBackError" />
</ClientEvents>

Remember you can handle any kind of situation with this, you just need to raise an execption and handle it on client side. You can use this technique with other control that support callback like combo box, tree view, call back etc.

Happy Coding

Labels: ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home