I have a javascript function tied to the click event of each checkbox item in an asp:checkboxlist. However, there's an option whereby the user can dynamically add a new item to the list. I have already successfully done this code, the item is added, and the javascript function tied to the onclick event. However, I need to run the onclick function once from the code behind, as I add the item to the list. How can I simply run a pre existing javascript function from C# codebehind?
protected void btnAddLang_Click(object sender, EventArgs e)
{
Healthline.ServiceRecords.DataHelper helper = new Healthline.ServiceRecords.DataHelper();
Hashtable prms = new Hashtable();
DataSet dsLangs = new DataSet();
prms = new Hashtable();
prms.Add("@LangName", txtOtherLanguages.Text);
dsLangs = helper.RunSP("mySP", prms);
if (dsLangs.Tables[0].Rows.Count > 0)
{
ListItem item = new ListItem();
item.Value = dsLangs.Tables[0].Rows[0]["LanguageID"].ToString();
item.Text = dsLangs.Tables[0].Rows[0]["Language"].ToString();
chkTopLanguages.Items.Add(item);
}
foreach (ListItem listitem in chkTopLanguages.Items)
{
listitem.Attributes.Add("onclick", "GetLanguages()");
}
//here I need to force an immediate call to the javascript function GetLanguages()
}
If it helps. Rather than a straight call to the javascript function, if I can force a trigger to the onclick event of the checkbox I just added, that should work as well, since the javascript function is called onclick of the checkbox item