473,804 Members | 3,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disabling .NET Controls Via JavaScript

Frinavale
9,735 Recognized Expert Moderator Expert
I've run into a bit of a problem concerning JavaScript and ASP.NET.

Upon page submission I disable all of my buttons and would also like to disable all of my inputs (Textboxes, DropDownLists, etc) as well. This will prevent multiple postbacks to the server while it's processing and keep the user from making changes during this time.

The problem is that when I use JavaScript to disable the input controls the values of these objects come back as nothing.

The JavaScript is quite simple:
Expand|Select|Wrap|Line Numbers
  1. function DisableAllInputs()
  2. {   var i;
  3.  
  4.     var allInputElements=document.getElementsByTagName('input');
  5.     var len=allInputElements.length;    
  6.     for(i = 0; i < len; i++)
  7.     {   
  8.         var temp = allInputElements[i];     
  9.         if(temp.type=="text")
  10.         {   temp.disabled=true;
  11.         }
  12.     }
  13.  
  14.     var allDropDownLists=document.getElementsByTagName('select');
  15.     var lenOfDDLs=allDropDownLists.length;
  16.     for(i = 0; i < lenOfDDLs; i++)
  17.     {   var temp = allDropDownLists[i];
  18.          temp.disabled=true;
  19.     }
  20. }
Does anyone have an idea of why the values of the TextBoxes and DropDownLists are nothing when the page is posted back to the server and JavaScript has been used disabled these controls?

-Frinny
Jul 10 '08 #1
2 1551
Frinavale
9,735 Recognized Expert Moderator Expert
I found the solution to my problem.

The reason why the controls had a value of nothing upon posting back to the server was because when you use JavaScript to disable the control it is removed from the Request.Form collection.

To get around the problem I used a <div> to place a "sheild" over top of the page's content:

Expand|Select|Wrap|Line Numbers
  1. <div id="shield" style="display:none; position:absolute; top:0; left:0; height:100%; width:100%; background-color:black; filter:alpha(opacity=35); opacity:.35;">&nbsp;</div>
  2.  
  3. <div id="maincontent">
  4.     <!-- the content of the page goes here-->
  5. </div>
  6.  
Now, when the page is submitted I call the following JavaScript function. It displays the "shield" over top of the entire page.

Expand|Select|Wrap|Line Numbers
  1. function DisplaySheild()
  2. {
  3.      document.getElementByID("sheild").style.display = 'block';
  4. }
Note that the style of the "shield" <div> has "position:absol ute", this is how the "shield" is displayed "on top" of the page content. Also note that I have the background colour of the "sheild" set and I am using opacity to allow the content under it to show through, you don't need to do this if you don't want to.

Hope this helps you!

-Frinny
Jul 10 '08 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Update: The <form> tag in asp.net has a property SubmitDisabledC ontrols.

If you set: submitdisabledc ontrols="True" then the controls disabled by the JavaScript code above will keep their values.

I'm sticking with my last solution because it disables link buttons etc. while the page is posting back.


Cheers!

-Frinny
Jul 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
3436
by: ML.Steve | last post by:
Hi, There are lots of posts on this subject but after a couple of hours of going though them I still can't get a number of fields to be disabled when a checkbox is ticked. Basically I have a lot of Forecast and Actual dates that can be entered, and next to each one an 'NA' checkbox that I want to disable/grey-out both dates (and the JavaScript calendar if possible). It also only has to work on Internet Explorer 6, as it is for...
2
7796
by: Jeelz | last post by:
Hi Guyz, Would appriciate any tip on disabling an ASP.NET LinkButton using client sided code like javascript. My Requirement is such that the user should be allowed to click on the link button only once (viz. he should not be allowed to submit the form twice). This stuff is easy when using a ASP:Button or HTML Button... but a link button has got me wondering how... plz help!
1
1638
by: john | last post by:
I have two different problems: 1. When the user has clicked on a button that is causing the browser to post back to the server, it could take a little while for the new page to show up. So in the mean time, I want to change the cursor to an hourglass and disable all of the controls on the form using javascript so the user can't do anything with any of the controls on the page. But when I disable certain controls (e.g. text boxes, radio...
4
2362
by: Dan =o\) | last post by:
Hi guys, in the scenario where a user fills in a form, and clicks on a button to Save, there's a period of waiting (the slower the connection between client and server, the longer the delay) where the user may be oblivious and could say, press the button twice, or even fill in some more data on the form... When the postback completes, any data entered in during this delay is lost. How do I, when the user clicks on a button, process...
3
1617
by: PB | last post by:
What is the rationalle for disabling JavaScript. AFAIK, the primary reason is for "security purposes" - but what specific kind of threats does the protect against? AND - is the disabling of JavaScript something that is done very much? I know it's impossible to answer that last question definitively - so I'm wondering if it has presented any of you with any real problems in the day-to-day running of your Web applications (i.e. support...
7
2236
by: John Meyer | last post by:
I have a program where I have to enable or disable a list box based upon a radio button. Is there an "enabled" property on select boxes?
11
12130
by: EagleRed | last post by:
I am writing an ASP.NET 2.0 application that uses master pages. I have some pages that must not be cached on the client. In ASP.NET 1.1 I achieved this using metatags: <meta http-equiv="Expires" content="0"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Cache-Control" content="no-cache"> This tags are part of the <headelement. Sample code that I have seen shows how to add metatags of the form:
3
3810
by: ChrisN | last post by:
Invoking a postback before a large ASP.NET page has fully rendered will often cause the page to crash. This is unhelpful and confusing to users. I'm wondering if I can overcome this by disabling any controls that invoke a postback until the page is fully rendered, ie setting the controls disabled server-side, serving the page and then having a JavaScript routine right at the bottom of the page re-enable them client-side.
5
4944
by: jehugaleahsa | last post by:
Hello: I am sure this question comes up a lot. I need to disable the controls on my Windows forms so that when the BindingSource is empty some the controls bound to it will be disabled. This will make it clear to the user that they have to create a new item first before they start working. This needs to be an easy process because there are many, many forms.
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10308
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10073
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9134
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7609
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5513
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.