Troubleshooting Problem with Disabled Dropdown in ASP.NET

I'm facing a situation with my ASP.Net webpage where I have specific rules for editing content:

  1. Normal users can only edit blank fields
  2. Admin users have the ability to edit all fields without any restrictions

To implement this, initially I attempted to use JavaScript to disable all fields that had values, but unfortunately, upon postback, all disabled fields lost their state. Therefore, I decided to set Readonly=true instead. Now, all textboxes are working as intended, however, dropdowns can still be edited even when readonly is true.

Is there a way to achieve this functionality without losing the control's value on postback?

Thank you in advance.

Answer №1

Implement the Enabled property on the server side.

Disable MyTextBox and MyDropDownList on the server side.
MyTextBox.Enabled = false;
MyDropDownList.Enabled = false;

Answer №2

I successfully implemented this solution with the help of jQuery library.

if (input.source === "select-one") {
  if ($(input.source).val() === "-1") { return true; }
  $(input.source).hide();
  $(input.source).after("<span class='disp_label' <b>" + input.source.options[input.source.selectedIndex].text + "</b></span>");
}

Big thanks to everyone who contributed!

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

Update the content of <p> depending on the selections made in two <select> elements

I am facing a challenge where I need to modify a price by altering the choices in two <select> tags. For instance: If a user selects Silver 1 in the first <select> and Silver 3 in the second <select>, then the resulting <p>value&l ...

Retrieve the maximum value for each date from MongoDB and store them in an array

Looking for the most effective method to obtain the top "score" for each "date" and save them in an array. Consider more than 50 scores for any given date. The structure of the database is as follows: { "_id" : ObjectId("5c06b91b583248493294"), "c ...

What is the best way to keep my data within a global variable?

$(function(){ let spaceTravelersData; $.getJSON('http://api.open-notify.org/astros.json', retrieveData); function retrieveData(data) { spaceTravelersData = data; } alert(spaceTravelersData.people[0].name) }); I a ...

Consistently showcasing images of varying dimensions that are unfamiliar

Currently, I'm in the process of developing a small web application that uses the Spotify API to fetch and showcase top tracks and artists to users. Each track or artist is presented within a Bootstrap panel, with the title displayed in the header an ...

Odd behavior observed while running npm scripts in the npm terminal

Included in my package.json file are the following dependencies: "devDependencies": { "chromedriver": "^2.37.0", "geckodriver": "^1.11.0", "nightwatch": "^0.9.20", "selenium-server": "^3.11.0" }, "scripts": { "e2e": "nightwatch -c test ...

developing educational material that can be unlocked

I am currently working on developing a web application for a small company that specializes in providing English courses for individuals looking to improve their language skills. I am facing a challenge in creating a form that, when completed correctly, gr ...

Refresh the view seamlessly using Ajax without reloading the page

When a button is clicked, the following code will run: $.ajax({ type: "POST", url: base_url+"/controller/method", data: {val: value}, success: function(data){ data = jQuery.parseJSON(dat ...

What is the best way to retrieve ember model relation properties within routes and controllers?

Currently using ember 2.7.0, I am facing an issue while setting up my ember app with a currentUser.organization derived from the authenticated token. Although I can successfully resolve the currentUser, I am encountering difficulties in resolving the prope ...

How can I prevent receiving redundant data and effectively manage my data?

I am currently working on adding offline support to my app. The logic I am following is to first check if there is cached feed data available. If the data is present, it will set the feeds to that cached data and display it from the cache. However, it will ...

Avoid inputting various symbols into the select2 field

I recently upgraded my select input to use select2: <select id="indivCitizen" multiple="multiple"> <option value=""></option> </select> To fetch data dynamically and enhance user experience: $(doc ...

Modify or delete strings using an array

Currently, I am utilizing Google Scripts which means it is purely JavaScript. The array that I am working with looks like this: [Tue Dec 23 00:00:00 GMT+00:00 2014, 816.43, Tue Jan 28 00:00:00 GMT+00:00 2014, 729.43] My goal is to reformat the date in o ...

Implement an Ajax handler in your Razor page

While I have experience with the customary MyPage.cshtml and MyPage.cshtml.cs files containing OnGetAsync and OnPostAsync methods, I am curious about how to incorporate an additional handler into the model page that can be invoked using JavaScript withou ...

What is the proper way to incorporate this jQuery slider plugin into my website?

I've successfully implemented the HTML and CSS, but I'm struggling with inserting the jQuery and plugin correctly. My familiarity with jQuery and JavaScript is limited, so I think I might be placing them in the wrong location, creating confusion ...

Applying a textured effect to a mesh in Three.js using JSON

When using THREE.js, I am facing difficulties loading a texture onto a mesh created from a JSON model. The code snippet below demonstrates loading a simple cube from models/cube.json: function loadRabbit() { // Load the Rabbit JSON data using a THREE ...

Learn how to transfer and retrieve data in a different jade template using Node.js without relying on session management or query strings

I am currently facing an issue where I need to redirect and send data from one view to another in a single step using Jade templates. The code snippet below shows my attempt: customer.js var express = require('express'); var router = express.Ro ...

Disabling the SOURCEMAP generation will result in the .css files not being minified

After taking a look at my React application in Chrome Developer Tools, I noticed that the Sources tab reveals a folder called static/js where the entire code of my project is visible. This discovery raised some red flags regarding security. To address thi ...

Passing data between the view and JavaScript in a Django application

Initially, I pass a JavaScript variable 'confirmed' to my Django view using a POST request. Then, a Python script processes this variable to perform certain actions. Finally, I aim to pass the processed data back to my HTML/JavaScript for display ...

The destroySlider() function of BxSlider fails to work due to either an undefined slider or a function that is not

I'm facing an issue with my carousel setup using bxslider. Here is the code snippet responsible for initializing the carousel: jQuery(document).ready(function() { var carouselWidth = 640; var carousel; var carousel_Config = { minSlides: 1, ...

There is an issue with the project where main.jsbundle, Foundation, and Security are missing, resulting in

I've noticed that I am missing the main.jsbundle file in my project and I'm unsure how to resolve this issue. Should I delete the file, or is there a specific step I can take to fix it? Attached is a screenshot showing where the file should be l ...

Having trouble with the product filter in Mongoose, unable to retrieve products

const mongoose = require("mongoose"); const { ObjectId } = mongoose.Schema; const productSchema = new mongoose.Schema( { title: { type: String, trim: true, required: true, maxlength: 32, text: true, }, ...