Solved

Using Javascript to disable asp dropdownlist

Posted on 2006-06-21
4
1,324 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
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 250 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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 …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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