Tao

Tao obeys its own inherent Nature

Add javascript to the client

 

Show how to add script to the client in aspx file.

/// <param name="rbl">RadioButtonList to apply script to</param>
/// <param name="page">The Page the script is going to be appended to</param>
/// <param name="script">The script to append</param>
public static void SetRadioButtonListItemScript(RadioButtonList rbl, Page page, string script)
{
for (int idx = 0; idx < rbl.Items.Count; idx++)
{
RegisterClientObjectFunction(page, rbl, idx, script);
}
}

/// <param name="page">The Page the script is going to be appended to</param> /// <param name="rbl">RadioButtonList to apply script to</param> /// <param name="idx">the index of the radio button</param> /// <param name="script">The script to append</param> static private void RegisterClientObjectFunction(Page page, RadioButtonList rbl, int idx, string script)
{
StringBuilder sw = new StringBuilder();
if (!page.IsStartupScriptRegistered(rbl.ClientID + "_" + idx.ToString() + "script"))
{
sw.Append(@"<SCRIPT>");
sw.Append(@"document.getElementById('" + rbl.ClientID + "_" + idx.ToString() + "').onclick=function() {" + script + "return true;}");
sw.Append(@"</SCRIPT>");
page.RegisterStartupScript(rbl.ClientID + "_" + idx.ToString() + "script", sw.ToString());
}
}

static private void RegisterClientObjectFunction(Page page, CheckBox chk, string script)
{
StringBuilder sw = new StringBuilder();
if (!page.IsStartupScriptRegistered(chk + "script"))
{
sw.Append(@"<SCRIPT>");
sw.Append(@"document.getElementById('"+chk.ClientID + "').onclick=function() {" + script + "return true;}");
sw.Append(@"</SCRIPT>");
page.RegisterStartupScript(chk.ClientID + "script", sw.ToString());
}
}

 

posted on 2007-08-30 18:34 wade 阅读(199) 评论(0)  编辑  收藏 所属分类: Dot.netJavascript


只有注册用户登录后才能发表评论。


网站导航:
 

导航

<2007年8月>
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

统计

常用链接

留言簿(7)

随笔分类

随笔档案

相册

Photo

搜索

最新评论

阅读排行榜

评论排行榜