Silverlight: Simple way to create call back method.

The Simple way to create a call back method in .Net. also you can pass on the value to the callback object inside the another call backmethod to your callbackmethod.


Private Guid userId;

public void SaveAndComplete(bool complete, Action onComplete)
{

userId=
//One more callback method.
_dc.SubmitChanges(SaveCompleted, onComplete);
}

private void SaveCompleted(SubmitOperation so)
{
if (!so.HasError)
{
//this is where you can pass on the value to the call back method.
((Action)so.UserState)(UserId);
}
else
{
//Error message
}
}


Calling the callback method "SaveAndComplete"

private void Save_Click(object sender, RoutedEventArgs e)
{
SaveAndComplete(false, SavedSuccessFully);
}
private void SavedSuccessFully(Guid generatedID)
{
//here you will get the value which you hve passed from the callback method.
if (generatedAssessmentID == Guid.Empty) return;

}

Comments

Popular posts from this blog

LINQ: Using int.TryParse() within a LINQ where clause

ASP.Net MVC: Configuring asp.net session state in SQL Server.

IIS: Publish Project to remote IIS with Web Deploy.