title: Put javascript on page from code behind
body: <p>I have some other javascript functions that are being set on the onfocus and onblur events of the textbox that I am using. In these functions it calls a generic javascript function that is not related to any controls. I want to know how to just simply spit this function out to the html of the page from the code behind. Something like this...</p>
  
  <pre><code>Page.ClientScript.RegisterStartupScript(this.GetType(), "?????", getCounter);
  </code></pre>
  
  <p>EDIT: Here is what I mean</p>
  
  <pre><code>public class MVADTextBox : TextBox
          {
   protected override void OnLoad(EventArgs e)
              {
   var getCounter = "&lt;script language=\"javascript\"&gt;" +
                                  "function GetCounter(input) {" +
                                      //this function gets the number of special characters taht are in a row.
                                      //it is only the grouping of characters that are right after your current position
                                      "var textbox = document.getElementById(input.id);" +
                                      "var mask = textbox.getAttribute('Mask');" +
                                      "var inputCharacters = textbox.getAttribute('InputCharacters');" +
                                      "var tbid = \"#\" + input.id;" +
                                      "var position = $(tbid).caret().start;" +
                                      "var counter = 0;" +
                                      "for (var i = position; i &lt; mask.length; i++) {" +
                                      "     if (mask[i] != '#') {" +
                                      "        counter++;" +
                                      "        if (mask[i + 1] == '#') {" +
                                      "            break;" +
                                      "        }" +
                                      "    }" +
                                      "}" +
                                      "return counter;" +
                                 " }" +
                              "&lt;/script&gt;";
  
                              Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OnFocus", onFocus);
                              Page.ClientScript.RegisterStartupScript(this.GetType(), "GetCounter(input)", getCounter);
  
  
  
  var onBlur = "&lt;script language=\"javascript\"&gt; function PopulateField(input) {if (input.value == \"\") {input.value = input.defaultValue; input.className = 'sampleText'; } } &lt;/script&gt;";
  
  
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OnFocus", onFocus);
  
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OnBlur", onBlur);
      }
  }
  </code></pre>
  
  <p>The on blur method is getting sent to the page.</p>