Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dropdown select (option 1, option 2 and option 3), when i select one of the options i would like a div show and hide that option.
i have jquery function in my source code but after postback it not work.

my code
JavaScript
<script type="text/javascript">


    $(document).ready(function () {

        $('.ddlFilter').change(function () {
            var sel = $(this).val();
            $('#div_date').hide();
            $('#div_subject').hide();
            $('#div_status').hide();

            if (sel === 'Date') {
                $('#div_date').show();
            }
            else if (sel == 'Subject') {
                $('#div_subject').show();
            }
            else if (sel == 'Status') {
                $('#div_status').show();
            }
        });

    }); 

    </script>

C#
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>   

 <div id="select">
            Filter Results by:

            <asp:DropDownList CssClass="ddlFilter"   ID="ddlFilterResultBy" 
                        runat="server" Width="221px"> 
                <asp:ListItem Text="Select..." Value=""></asp:ListItem> 
                <asp:ListItem Text="Date" Value="Date"></asp:ListItem> 
                <asp:ListItem Text="Subject" Value="Subject"></asp:ListItem> 
                <asp:ListItem Text="Status" Value="Status"></asp:ListItem> 
            </asp:DropDownList> 

            </div>
            <div id="holder">
            <div id="div_date" style="width: 250px; display: none;" class="sectionrowDate">
                Date Range:

               <%-- <uc1:DatePicker ID="dpFromDate"  runat="server"   />
                <uc1:DatePicker ID="dpToDate"  runat="server"  />--%>
            </div>
            <div id="div_subject" style="display: none;" class="sectionrow">
                Subject: 
                <asp:TextBox ID="txtSubject" runat="server" Width="225px" SkinID="Picker"></asp:TextBox>
            </div>

            <div id="div_status" style="display: none;" class="sectionrow">
                Status:

                <asp:DropDownList  ID="ddlStatus" runat="server" Width="152px">
                </asp:DropDownList>

            </div> 
            </div>

            <asp:Button ID="btnSearch" Text="Search" runat="server" OnClick="btnSearch_Click" />
        </div>
         </ContentTemplate>
    </asp:UpdatePanel>


very first time this function work very well but after postback it not work.


How can this be accomplished?
Posted
Updated 13-May-13 23:05pm
v2

you can refer here
 
Share this answer
 
When your using ScriptManager u need to registers event's as below


C#
var prm = Sys.WebForms.PageRequestManager.getInstance();
  prm.add_endRequest(BindEvents);
  function BindEvents() { 
    $(document).ready(function () {
 
        $('.ddlFilter').change(function () {
            var sel = $(this).val();
            $('#div_date').hide();
            $('#div_subject').hide();
            $('#div_status').hide();
 
            if (sel === 'Date') {
                $('#div_date').show();
            }
            else if (sel == 'Subject') {
                $('#div_subject').show();
            }
            else if (sel == 'Status') {
                $('#div_status').show();
            }
        });
 
    }); 
}
 
Share this answer
 

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