?
Solved

Using Javascript to disable asp dropdownlist

Posted on 2006-06-21
4
Medium Priority
?
1,352 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

771 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