title: Get from name in asp.net masterpage for javascript in sub-page
body: <p>I have an asp.net website that uses masterpages.  I am trying to use jquery to validate some fields in my subpage.  But jquery wants to know the name of the form.  As you know, the form is created on the masterpage.  I have been unable to get the form in my javascript in the subpage.</p>
  
  <p>I tried to use:</p>
  
  <pre><code>var form = $('&lt;%= form1.ClientID %&gt;');
  </code></pre>
  
  <p>But it will not even launch the page from Visual Studio because it says form1 does not exist.  So I moved that line into the masterpage hoping the form variable would still be in scope for my javascript in the subpage.  I will past some of my code below.  Any help on how I can do this would be great.</p>
  
  <p>MasterPage:</p>
  
  <pre><code>&lt;%@ Master Language="C#" AutoEventWireup="true" CodeBehind="myMaster.master.cs" Inherits="myMaster" %&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;My Site&lt;/title&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;link rel="stylesheet" href="mymain.css" /&gt;
  
      &lt;!-- Scripts --&gt;
      &lt;script src="assets/js/jquery.1.11.1.min.js"&gt;&lt;/script&gt;
      &lt;script src="assets/js/jquery.min.js"&gt;&lt;/script&gt;
  
      &lt;asp:ContentPlaceHolder ID="HeaderPlaceHolder" runat="server" /&gt;
  &lt;/head&gt;
  &lt;body class="no-sidebar"&gt;
      &lt;form runat="server" id="myMaster"&gt;
      &lt;div id="page-wrapper"&gt;
          &lt;!-- Main Wrapper --&gt;
          &lt;asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" /&gt;
  
          &lt;script&gt;
              $(document).ready(function () {
                  var form = $('&lt;%= masterForm.ClientID %&gt;');
          });
          &lt;/script&gt;
      &lt;/div&gt;
      &lt;asp:ContentPlaceHolder ID="BottomPlaceHolder" runat="server" /&gt;
      &lt;/form&gt; 
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Sub-Page:</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="myMaster.Master" AutoEventWireup="true" CodeBehind="subpage.aspx.cs" Inherits="subpage" %&gt;
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="HeaderPlaceHolder" runat="server"&gt;
  &lt;!-- Stylesheets --&gt;
  &lt;link rel="stylesheet" href="jforms.css"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"&gt;
  
  &lt;div class="wrapper wrapper-640"&gt;
      Validate Me.
  &lt;/div&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content3" ContentPlaceHolderID="BottomPlaceHolder" runat="server"&gt;
      &lt;script src="assets/js/jquery.maskedinput.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
          $(document).ready(function () {
              alert(form);
          });
  &lt;/script&gt;
  &lt;/asp:Content&gt;
  </code></pre>