tags:

views:

69

answers:

2

I have month drop down and the save button , i want to disable the save button if the value from the month drop down is selected as previous month in asp.net webpage

+1  A: 

You should use javascript for this. Use this function on onchange="checkdate()" of your drop down you can also set it from code behind file. write this in Page_Load function of your page...

 ddlMonths.Attributes.Add("onchange", "checkdate()");

Suppose that ddlMonths is your dropdown Id

function checkdate()// to check Month
{
    var ddlMonths = document.getElementById('<%=ddlMonths.ClientID %>');
    var btnSave =document.getElementById('<%=btnSave.ClientID %>');
    var lCurrentMonth = (new Date()).getMonth();

     if(ddlMonths.options[ddlMonths.selectedIndex].value < lCurrentMonth) 
          btnSave.disabled= true;
     else
         btnSave.disabled= false;
}

will give you the 1 less then month number starting from zero suppose that you give values to your MOnths in list starting from 0 to 11 or you can set it accordingly, you can add 1 into Months if you start from 1-12

Azhar
A: 

If it's a regular dropdown with only one option to select, the onchange-function could be shortend

function checkDate() {
    var doc = document;

    var btn = doc.getElementById('<%=btnSave.ClientID %>');
    var slc = doc.getElementById('<%=ddlMonths.ClientID %>');

    btn.disabled = (slc.selectedIndex < (new Date()).getMonth());
}
john_doe