#DEBUG Preprocessor statements in ASPX page

前端 未结 8 1020
滥情空心
滥情空心 2020-12-29 22:09

I\'m trying to use a preprocessor directive in an ASPX page, but the page doesn\'t recognize it. Is this just something I can\'t do?

Background: I\'m trying to inclu

相关标签:
8条回答
  • 2020-12-29 22:56

    A better approach may be to use server side code to include the script. I'd use something like

    protected void Page_Load(object sender, EventArgs e)
    {
    #if DEBUG    
        ScriptManager.RegisterClientScriptInclude(this, this.GetType(), "JQueryScript", "resources/jquery-1.3.2.js");
        #else
        ScriptManager.RegisterClientScriptInclude(this, this.GetType(), "JQueryScript", "resources/jquery-1.3.2.min.js");
        #endif
    }
    
    0 讨论(0)
  • 2020-12-29 23:03

    I don't think you can have preprocessor directives in the aspx unfortunately.

    A simpler way to go is to simply have a property in your code-behind that feeds in the jQuery URL, then you can set preprocessor directives to declare it. Or if you'd prefer to keep the URL in the code-infront you could use a Literal control and toggle their visibility in the code-behind based on the processor directives.

    For example:

    code-infront:

    <asp:literal id="litJQuery" EnableViewState="false" runat="Server">
    <script type="text/javascript" src="resources/jquery-1.3.2.js" />
    </asp:literal>
    <asp:literal id="litJQueryDebug" EnableViewState="false" Visible="false" runat="Server">
    <script type="text/javascript" src="resources/jquery-1.3.2.min.js" />
    </asp:literal>
    

    code-behind, in the Page_Load method:

    #if DEBUG
    litJQueryDebug.Visible=true;
    litJQuery.Visible=false;
    #endif
    
    0 讨论(0)
提交回复
热议问题