最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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 piled 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 piler understand that it has to skip the Javascript?

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 piled 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 piler understand that it has to skip the Javascript?

Share Improve this question asked Nov 13, 2012 at 10:15 CiccioMiamiCiccioMiami 8,27634 gold badges96 silver badges158 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 3

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>
发布评论

评论列表(0)

  1. 暂无评论