Prev | Current Page 507 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

innerHTML = values[1];
vehLst.appendChild(option);
}
}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"LoadVehicles", clientRecFunc.Replace("$list",CbVehicleLst.ClientID),
true);
LoadVehicles takes the results from the server-side callback as well as a context parameter
and uses the data to load the data into the client side rendering of the CbVehicleList ListBox
control. The script text has a placeholder for the name of the control; it is replaced at registration
time with the actual ClientID property of the ListBox.
The other interesting item of note is the encoding mechanism used to send vehicle data to
the client, which is best understood by looking at the web form??™s implementation of
ICallbackEventHandler.
public void RaiseCallbackEvent(string eventArgument)
{
cbVehicles = GetVehiclesByCategory(eventArgument);
}
public string GetCallbackResult()
{
string result = "";
foreach (Vehicle veh in cbVehicles)
{
result += veh.Name + ":" + veh.Description + ";";
}
return result;
}
The Vehicle class has two properties named Name and Description, which are serialized
into a string. The properties are separated with a colon and returned instances are separated by
CHAPTER 8 ?–  INTEGRATING CL IENT-SIDE SCRIPT 399
semicolons.


Pages:
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519