How Call JavaScript function for DropDownList OnSelectedIndexChanged with AutoPosBack true

Last Reply on Nov 16, 2012 06:59 AM By Mudassar

Posted on Nov 16, 2012 06:48 AM


I Have One DropDownList Which contains Months of Year which is as below

Select Month <asp:DropDownList ID="drpmonths" AutoPostBack="true" runat="server" 
        Width="121px" onselectedindexchanged="drpmonths_SelectedIndexChanged">
 <asp:ListItem Value="1">January</asp:ListItem>
        <asp:ListItem Value="2">February</asp:ListItem>
        <asp:ListItem Value="3">March</asp:ListItem> 
so on

and im trying to validate on client side only when user selects Month Greater than present month so i write one Javascript

<script type="text/javascript">
    function validmonth()
    var month = document.getElementById('<%=drpmonths.ClientID%>').selectedIndex;
    var d = new Date();
    var n = d.getMonth();
    if (month > n) {
        alert('Selected Month is greterthan Todays Month');


is one function is der..

You are viewing reply posted by: Mudassar on Nov 16, 2012 06:59 AM.
Posted on Nov 16, 2012 06:59 AM

This way

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1"
        onchange="return Validate();">
        <asp:ListItem Text="One" Value="1"></asp:ListItem>
        <asp:ListItem Text="Two" Value="2"></asp:ListItem>
    <script type="text/javascript">
        function Validate() {
            if (confirm("Do you want to submit?")) {
                __doPostBack("<%=DropDownList1.UniqueID %>", "");
            return false;
    protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
        ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Event Fired')", true);




I agree, here is the link: