Add(txt);
list = new DropDownList();
Controls.Add(list);
div = new HtmlGenericControl("div");
Controls.Add(div);
if (dataBinding)
{
IEnumerator e = dataSource.GetEnumerator();
while (e.MoveNext())
{
string symbol = e.Current.ToString();
ListItem item = new ListItem(symbol, symbol);
list.Items.Add(item);
count++;
}
}
CHAPTER 8 ?– INTEGRATING CL IENT-SIDE SCRIPT 409
else
{
IEnumerator e = dataSource.GetEnumerator();
while (e.MoveNext())
{
ListItem item = new ListItem("", "");
list.Items.Add(item);
count++;
}
}
CreateClientScript();
}
return count;
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
RaiseCallbackEvent(list.SelectedValue);
div.InnerHtml = GetCallbackResult();
}
private void CreateClientScript()
{
list.Attributes.Add("onChange",
"GetNews(this.options[this.selectedIndex].value)");
string clientRecFunc = @"
function LoadNews(results, context)
{
var newsDiv = document.getElementById('$div');
newsDiv.innerHTML = results;
}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"LoadNews", clientRecFunc.Replace("$div", div.ClientID),
true);
string callBack = Page.ClientScript.GetCallbackEventReference(
this, "symbol", "LoadNews", null);
string clientCallFunc = "function GetNews(symbol){ " +
callBack + "; }";
Page.
Pages:
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529