Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using Javascript to disable asp dropdownlist

Posted on 2006-06-21
4
Medium Priority
?
1,355 Views
Last Modified: 2010-05-18
Check this problem out:  

I have two asp:dropdownlist controls on a page.  If you select option 3 in the first drop down, then the second drop down should become disabled.  If you select anything other than option 3 in the first drop down, then the second dropdown should be (re)enabled.

It would be nice to do this client-side.  Can javascript do this?
0
Comment
Question by:Cansler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 1000 total points
ID: 16951081
<script language="javascript">
function CheckDropDownState(lstbox)
{
   if (lstBox.selectedIndex == 2)
   {
       document.forms[0].DropDown1.disabled = 1;
   }
   else
   {
      document.forms[0].DropDown1.disabled = 0;
   }
}
</script>

ASPX.VB
----------
DropDown1.Attributes.Add("onChange","javsacript:CheckDropDownState(this);")

-Nauman.
0
 

Author Comment

by:Cansler
ID: 16951143
Sweet.  Where does the Attributes.Add line go...PageLoad?
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 16951171
Yes. Add it in PageLoad() event.

-Nauman.
0
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16951268
hi,
try
this
 'Server Side
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
             DropDownList1.Attributes("onchange") = "ChangeDrpDown2()"
    End Sub

//Client side java script
function ChangeDrpDown2()
            {
            
                if(document.Form1["DropDownList1"].options.value==3)
                {
                  document.Form1["DropDownList2"].disabled=true;
                }
                else
                {
                 document.Form1["DropDownList2"].disabled=false;
                }
            }

regards
pradeep
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question