Click here to Skip to main content
15,918,243 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application i have two drop downs one is year drop down and second is month drop down and below is my jquery function
which i had used to display loading image on the selection change of each drop down but this javascript function is working only for 
first time of my drop down selection and it is working only for one drop down it is not showing for second drop down i had tried 
with onchange event also by calling it in my dropdownlist but its not working


<pre lang="Javascript"><script type="text/javascript">
            $(function year() {
                $(".modal1").hide();
                $("#ddlYear").change(function year() {
                    $(".modal1").show();
                    var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
                    var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
                    modal1.css({ top: top, left: left });
                });
            });
           
        </script>
    <script type="text/javascript">
        $(function month() {
            $(".modal1").hide();
            $("#ddlMonth").change(function month() {
                $(".modal1").show();
                var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
                var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
                modal1.css({ top: top, left: left });
            });
        });
    </script>
<asp:DropDownList ID="ddlYear" runat="server" Height="22px" Width="121px" OnSelectedIndexChanged="ddlYear_SelectedIndexChanged" onchage="validate year();" AutoPostBack="True">
 <asp:DropDownList ID="ddlMonth" runat="server"  Height="22px" Width="121px" AutoPostBack="True" onchage="validate month();"  OnSelectedIndexChanged="ddlMonth_SelectedIndexChanged">


What I have tried:

i had tried by calling my function in ochnage of drodownlist but its not wroking
Posted
Updated 25-Oct-17 21:26pm
Comments
Karthik_Mahalingam 25-Oct-17 5:30am    
are you using update panel ?
Member 12324523 25-Oct-17 5:34am    
yes i am using update panel
Member 12324523 25-Oct-17 6:39am    
Can anyone help me out how to resolve this
Karthik_Mahalingam 25-Oct-17 8:34am    
how you are hiding the modal after open ?

1 solution

refer this example

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
     
    <style>
        .modal1 {
            width:200px;
            height:150px;
            background-color:gray;
        }
    </style>
    <script> 

        $(function () {

            $(".modal1").hide();
            $( '#<%= ddlYear.ClientID %>'  + ',#<%= ddlMonth.ClientID %>').change(function () {
                $(".modal1").show(); 
            });
             
        });

        function pageLoad() {   // use this when you are using update panel
            $(".modal1").hide();
        }


        function close(){
            $(".modal1").hide();
        }


    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>

                <asp:DropDownList ID="ddlYear" runat="server" Height="22px" Width="121px" OnSelectedIndexChanged="ddlYear_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>
                <asp:DropDownList ID="ddlMonth" runat="server" Height="22px" Width="121px" AutoPostBack="True" OnSelectedIndexChanged="ddlMonth_SelectedIndexChanged"></asp:DropDownList>
            </ContentTemplate>

        </asp:UpdatePanel>
        <br /><br /><br />
        <div class="modal1"  >
            <div style="text-align:right">
         <button onclick="close()">close</button>
                </div>
            <h1>Loading..</h1>
        </div>
    </form>
</body>
</html>



protected void Page_Load(object sender, EventArgs e)
     {
         if (Page.IsPostBack) return;
         for (int i = 0; i < 10; i++)
             ddlYear.Items.Add("Year-" + i);


         for (int i = 0; i < 10; i++)
             ddlMonth.Items.Add("Month-" + i);

     }


     protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
     {
         System.Threading.Thread.Sleep(2000); // for testing purpose to create a delay
     }

     protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
     {
         System.Threading.Thread.Sleep(2000); // for testing purpose to create a delay
     }


refer .net - What's the different between ASP.NET AJAX pageLoad() and JavaScript window.onload? - Stack Overflow[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900