Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6181455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:01:35+00:00 2026-05-24T01:01:35+00:00

I have gleaned that it is possible to use conditional compiler directives and constants

  • 0

I have gleaned that it is possible to use conditional compiler directives and constants in Razor markup. I would like to know if there is a way to conditionally emit JavaScript text using these directives, as I seek to to below:

@section BodyPanelScript
{
    <script type="text/javascript">
        $(function () {
            $(":password").val(null);

            // Back up current names of package radio buttons, then make all their names the same for grouping.
            $("#package-selector :radio[name$='.IsSelected']").each(function () {
                $(this).attr("oldname", $(this).attr("name"));
            });
            $("#package-selector :radio[name$='.IsSelected']").attr("name", "Package.IsSelected");

            // Hook the 'submit' click to restore original radio button names.
            $("form#register :submit").click(function () {
                $(":radio[name='Package.IsSelected']").each(function () {
                    $(this).attr("name", $(this).attr("oldname"));
                });
            });

        });    
    </script>
    @{
#if AUTO_FILL_REG
        <text>
        <script type="text/javascript">
            $(function () {
                $(":password").val("123456");
            });    
        </script>
        </text>
#endif
    }
}

The constant AUTO_FILL_REG is defined in my Debug configuration, and tells the controller to populate the registration model with default values, so I don’t have to always complete the form to test the process. Existing values in the model are ignored on the password field, so I resort to some JavaScript to populate this field. I would like to have this JavaScript conditionally emitted, but several attempts like the code above either result in the #if...#endif text being literally rendered, and the password populated, or nothing being rendered, regardless of build configuration.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:01:36+00:00Added an answer on May 24, 2026 at 1:01 am

    This is not a particularly elegant solution, but it is simple. You can make a simple class like this

    public static ConditionalValue {
      public static bool AUTO_FILL_REG {
        get {
    #if DEBUG
          return true;
    #else
          return false;
    #endif 
        }
      }
    }
    

    and then just reference this in your aspx. This is just one example of where you could place this property. You could do it as constants as well, but you get the idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that I would like to embed inside our companies CMS.
I have some Scala code that makes fairly heavy use of generics, and I
Have an app that can use tts to read text messages. It can also
Have you ever seen any of there error messages? -- SQL Server 2000 Could
I have a simple document-based Cocoa app that acts as a viewer for .wav
I have something roughly like the following. Basically I need to access the class
One thing I have continually found very confusing about using an object database like
Have noticed issue while testing iphone app that if one quickly opens/dismisses a modal
Have you seen library for flexible working with terminal(Unix like)? I want to implement
have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.