title: Server side variables in javascript
body: <p>I suppose this isn't a huge deal, since there are other way around this issue, but I'm really curious as to the answer, since I thought this was possible to do.</p>
  
  <p>I have a public property that returns a boolean in my code behind. I'd like to access this server variable in my javascript validation function, but so far, not quite getting it.</p>
  
  <pre><code>Public Property editMode() As Boolean
      Get
          If Cache("editMode") IsNot Nothing Then
              Return (DirectCast(Cache("editMode"), Boolean))
          Else
              Return False
          End If
      End Get
      Set(ByVal value As Boolean)
          Cache("editMode") = value
      End Set
  End Property
  
  function validateEdit()
  {
      alert("editMode value is " + '&lt;%#editMode()%&gt;');
      if ('&lt;%#editMode()%&gt;'.toString() == "True")
      {
          alert("You are currently in edit mode. Please save or cancel changes.");
          return false;
      }
      return true;
  }
  </code></pre>
  
  <p>I've tried a bunch of variations on this, but it's always False. In the current code the alert returns "editMode value is False"</p>
  
  <p>When I use:</p>
  
  <pre><code>if ('&lt;%#editMode()%&gt;') ...
  </code></pre>
  
  <p>Then it's still always False, but it goes into the if condition, so the behaviour is as if it were always true.</p>
  
  <p>One other thing to mention is that most javascript/server tag stuff I find says to use <strong>&lt;%=editMode %></strong>, but I can't do this because every time I use the = instead of the # I get an exception: </p>
  
  <blockquote>
    <p>"The Controls collection cannot be
    modified because the control contains
    code blocks (i.e. &lt;% ... %>)."</p>
  </blockquote>
  
  <p>So I solved this by using # and saying </p>
  
  <pre><code>    Page.Header.DataBind()
      Page.Form.DataBind()
  </code></pre>
  
  <p>In the page load event handler.</p>
  
  <p>Any ideas? Thank you in advance. :)</p>
  
  <p>(Also, I usually use C#, so I might have unknowingly done something goofy in the VB part, so feel free to point that out too)</p>