I have searched how to register a Javascript in the code behind file .cs but still have not understand it and what I have tried does not fire the Javascript.
How can I fire an existing javascript function within the
protected void Page_Load(object sender, EventArgs e)
{
}
I have tried
Page.ClientScript.RegisterStartupScript(Type.GetType, "script", "return myFunction()");
But it says that it has invalid arguments? and a bunch of exceptions when I hover the red underline.
Thank you for your help.
Function
function myFunction() {
var combo = $find("<%= myClients.ClientID %>");
//prevent second combo from closing
cancelDropDownClosing = true;
//holds the text of all checked items
var text = "";
//holds the values of all checked items
var values = "";
//get the collection of all items
var items = combo.get_items();
//enumerate all items
for (var i = 0; i < items.get_count(); i++) {
var item = items.getItem(i);
//get the checkbox element of the current item
var chk1 = $get(combo.get_id() + "_i" + i + "_chk1");
if (chk1.checked) {
text += item.get_text() + ",";
values += item.get_value() + ",";
}
}
//remove the last comma from the string
text = removeLastComma(text);
values = removeLastComma(values);
if (text.length > 0) {
//set the text of the combobox
combo.set_text(text);
}
else {
//all checkboxes are unchecked
//so reset the controls
combo.set_text("");
}
}