title: How to register a Javascript on Load
body: <p>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.</p>
  
  <p>How can I fire an existing javascript function within the</p>
  
  <pre><code>  protected void Page_Load(object sender, EventArgs e)
     {
     }
  </code></pre>
  
  <p>I have tried </p>
  
  <pre><code>Page.ClientScript.RegisterStartupScript(Type.GetType, "script", "return myFunction()");
  </code></pre>
  
  <p>But it says that it has invalid arguments? and a bunch of exceptions when I hover the red underline.</p>
  
  <p>Thank you for your help.</p>
  
  <p>Function</p>
  
  <pre><code>function myFunction() {
              var combo = $find("&lt;%= myClients.ClientID %&gt;");
              //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 &lt; 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 &gt; 0) {
                  //set the text of the combobox
                  combo.set_text(text);
              }
              else {
                  //all checkboxes are unchecked
                  //so reset the controls
                  combo.set_text("");
              }
          }
  </code></pre>