473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Disabling .NET Controls Via JavaScript

Frinavale
9,735 Expert Mod 8TB
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 1528
Frinavale
9,735 Expert Mod 8TB
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:absolute", 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 Expert Mod 8TB
Update: The <form> tag in asp.net has a property SubmitDisabledControls.

If you set: submitdisabledcontrols="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
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...
2
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...
1
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...
4
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)...
3
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...
7
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
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...
3
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...

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.