Insert Javascript into content page in ASP.NET without compiling it

14,605

You have to write the if statement in VB language.

<asp:Content ID="Content4" ContentPlaceHolderID="javascript" runat="server">

<script language="javascript" type="text/javascript" >

function showErrors() {
      var id = '<%=Request.QueryString("id") %>';
      <% If Request.QueryString("errors") = "true" Then  %>
          var errorCode = '<%=Request.QueryString["errorCode"] %>';
          var errorMessage = '<%=Request.QueryString["errorMessage"] %>';
      <% End If %>
    }
</script>
</asp:Content>
Share:
14,605
CiccioMiami
Author by

CiccioMiami

Updated on June 29, 2022

Comments

  • CiccioMiami
    CiccioMiami almost 2 years

    I have an ASP.NET Web Forms application in VB.NET

    In my application I use a Master Page and to insert Javascript for a specific page I use a ContentPlaceHolder.

    I have a Javascript where I use code nuggets and I inserted in my page like this:

    <asp:Content ID="Content4" ContentPlaceHolderID="javascript" runat="server">
    
    <script language="javascript" type="text/javascript" >
    
    function showErrors() {
          var id = '<%=Request.QueryString("id") %>';
          <%if (Request.QueryString("errors") == "true")  {%>
              var errorCode = '<%=Request.QueryString["errorCode"] %>';
              var errorMessage = '<%=Request.QueryString["errorMessage"] %>';
    <%} %>
        }
    </script>
    </asp:Content>
    

    The problem is that when I build the solution, also the Javascript code gets compiled and of course syntax errors are found. For instance one of the build errors is related to the if statement that does not have a matching End If (as it is supposed to be in VB.NET)

    How can I make the compiler understand that it has to skip the Javascript?