Question

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?

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top