Dynamic HTML Rendering based on ASP.NET Web.config Key

I need to control the visibility of certain markup based on a key in the web.config file. The key is defined as follows:

<add key="IsDemo" value ="true"/>

I am looking for a way to show or hide the markup for a non-server HTML element without using a code-behind file, as there are no .cs files and no runat=server controls. Is there a way to achieve this using only ASPX markup? I am thinking of something like the following pseudo code:

IF ( IsDemo == "true" )
THEN
<tr>
    <td id="tdDemoSection" colspan="2" align="left" valign="top">
        <.....>
    </td>
</tr>
ENDIF

Can anyone provide guidance on implementing such conditional logic in ASPX markup? Your help is greatly appreciated.

EDIT:

The section I want to show or hide contains sensitive data like usernames and passwords. Therefore, I need to ensure that the markup is not visible to users using tools like Firebug or Web Developer Tools. The markup should remain hidden on the client side.

Answer №1

If you were to write code for a similar scenario, it would look something like this:

<% if(System.Configuration.ConfigurationManager.AppSettings["IsDemo"] == "true") %>
<% { %>
<!-- Insert protected HTML content here -->
<% } %>

This example assumes that you are working with C#.

To ensure the code is more robust, consider adding checks for scenarios where the AppSettings value is null or other edge cases.

Answer №2

Solution:

<% if (ConfigurationManager.AppSettings("IsDemo").ToLower().Equals("true")) Then%>
    <div>
       <.....>
    </div>
<% else%>
    <div>
        <.....>
    </div>
<% end if%>

Answer №3

From my understanding, if you are looking to avoid server-side components (such as aspx components with runat="server"), and solely want to manage the display of HTML on your aspx page, you can consider the following approach.

Start by creating a property in the codebehind file (or alternatively in a separate configuration helper class):

//IN C# (OR VB) file
protected string Demo{
    get{ 
            return ConfigurationManager.AppSettings["IsDemo"]=="true"?
                   "none":"block";
      }
}

Now in your aspx page:

<tr style="display:<%= Demo%>;">
    <td>blah blah</td>
</tr>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you explain the distinction between using this.function and making a function call in React?

I'm new to React and recently came across some code in a project that confused me. Could someone please clarify the distinction between this.function and the following function call used in a React event handling prop? <button onClick={this.clickH ...

vb.net making multiple requests with WebClient is experiencing performance issues

Here's the scenario I'm facing: Using Javascript, I am making 6 AJAX requests to vb.NET pages. $.ajax({type: 'POST', url: "/ajax/ajax.aspx?c=1"}); $.ajax({type: 'POST', url: "/ajax/ajax.aspx?c=2"}); $.ajax({type: &apos ...

What is the best way to simulate an unexported function in Javascript jest environments?

Testing a module in my vuejs project is what I'm currently focusing on. import { getBaseUrl } from "@/application/api/baseUrl"; export default ( uri: string, requestBody: Record<string, string | number> ): void => { let form ...

Choose just one button from the variety of buttons available

I am facing an issue with a component that contains multiple cards, each with its own button. Below is the code for this component: import React, { useState, useEffect } from "react"; import "./App.css"; import { Card, Container, Row, C ...

What are the steps to create two frames using Twitter Bootstrap?

I'm just starting to work with Twitter Bootstrap and I need some help. Can someone assist me in creating a two-column layout inside the HTML, where the menu in the header stays visible even when scrolled down? I've included my HTML code below. Th ...

What is the best way to change the value of a key in a JSON Object?

I am currently utilizing _underscore library. My goal is to change the value of a specific key. var users = [{ "_id": { "$oid":"3426" }, "name":"peeter" }, { "_id": { "$oid":"5a027" }, "name":"ken" }, { "_id": { "$oid":"5999" }, ...

Three.js - Exploring the Significance of "THREE" within the THREE.scene Framework

Just starting out in JavaScript and experimenting with animations using three.js library. I'm trying to grasp the meaning behind: const scene = new THREE.Scene(); Why is the "THREE" necessary in THREE.Scene? Could we not simply write const scene = n ...

Utilizing SlickGrid and DataView for calculating totals efficiently without the need for grouping

I am attempting to utilize Slick Grid and DataView to calculate column totals similar to the example shown here: . However, I do not want to group my rows. Therefore, I attempted not passing a getter and formatter into the dataView.setGrouping(..) method. ...

"Learn how to efficiently incorporate data into data-binding in VUE JS with just a

In my data binding, there is a string that reads as follows: bc-men,bc-men-fashion,bc-men-underwear I want to create an input field where I can enter "bc-some-category", click "Add", and have it appended to the end of the list with a comma in front. Her ...

Changing the value of a JavaScript variable within the .Net Codebehind

I've run into an issue where I need to update a JavaScript variable after post-back. My initial approach was to use the ClientScript.RegisterStartupScript function, which worked fine during the first page load but failed on subsequent postbacks. I inc ...

Encountering issues with Webpack 2 failing to resolve the entry point specified in the

Encountering an issue while trying to compile my application with webpack 2. This is how my app folder structure looks: / | - dist/ | | - src/ | | | | - modules/ | | | | | | - module1.js | | | | - index.js * | | _ webpack.config.js | | ...

What is the best way to automatically log out a user once their session cookie has expired during an online exam?

While developing an MVC ExpressJS Test app, I encountered an issue with auto-logout functionality for users who stop answering test questions. The error message "Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client" keeps app ...

Leveraging Twitter Bootstrap within an ASP.NET development endeavor

I am embarking on my first ASP.NET website project and I have a strong desire to incorporate Twitter Bootstrap into it. However, I am facing some challenges right from the start. After downloading the Zip file from this link, I unzipped it and added the n ...

Encountering a problem when trying to send an API request for multer in order to save

I encountered an issue with my node API that uses multer to store files. I am receiving an error when calling it and seeking assistance. Below is the code snippet along with the specific error message - Code - const storage = multer.diskStorage({ d ...

Utilizing Node JS to transfer information from an array of objects into a Postgres table

After spending the entire day trying to work with JSON data and Postgres, I still can't figure out what's causing the issue. This is a snippet of my dataset, consisting of around 1000 objects: { avgHighPrice: null, highPriceVolume: 0, ...

Sending an array as a reference parameter in a delegate function

After attempting to tackle the HackerRank challenge, I stumbled upon a C++ algorithm created by @DNKpp and shared on this platform. I decided to convert it into a functioning C# version: class Demo { delegate int MyDelegate(int[] _scores, int _aScore) ...

Having issues with my project as the Three.js Scene is malfunctioning and the THREE object is not

My attempt at creating my first three.js project has hit a roadblock. After following a tutorial, I expected to see a black scene upon loading the page, but all I'm getting is a white screen. Errors in Chrome Browser Console: three.js:1 Failed to lo ...

The text is not appearing properly in an HTML file due to issues with

Hi trying to display the text received from the controller's scope. Here's what I have attempted: HTML: <div ng-repeat="item in sResults"></div> Controller JavaScript: $scope.sResults = []; function App( ){ var Label ...

Troubleshooting 404 AJAX Error in ASP.NET Core and Visual Studio 2022

I have been struggling for hours trying to make Ajax work, even after looking at numerous examples. I just can't seem to get it right. Below is a snapshot of my layout. I am using Visual Studio 2022 along with ASP.NET Core. Calling all experts - wha ...

Trigger the submission of Rails form upon a change in the selected value within a dropdown form

I am working on a Rails application that has a table of leads. Within one of the columns, I display the lead's status in a drop-down menu. My goal is to allow users to change the lead's status by simply selecting a different value from the drop-d ...