【问题标题】:Handle click event of dropdown in c# by jquery通过jquery处理c#中下拉菜单的点击事件
【发布时间】:2015-08-05 07:42:20
【问题描述】:

我已经在 aspx 文件中编写了代码

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
        <section>
            <div>
            <label>State</label>
            <label class="select">
                <asp:DropDownList ID="ddlState" runat="server" DataTextField="StateName" DataValueField="StateName">
                </asp:DropDownList><i></i>
            </label>
            </div>
        </section>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddlCountry" />
    </Triggers>
</asp:UpdatePanel>

<div>
    <label>Country</label>
    <label class="select">
        <asp:DropDownList ID="ddlCountry" runat="server" ToolTip="Select country" DataTextField="CountryName"
        DataValueField="CountryID" AutoPostBack="true" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged">
        </asp:DropDownList><i></i>
        <asp:Label ID="lblSelectCountryFirst" Visible="false" Text="Please Select Country" runat="server" ForeColor="Red">
        </asp:Label>
    </label>
</div>

</section>

现在我希望当用户单击状态下拉列表时,标签 lblSelectCountryFirst 应该是可见的。如何在 jquery 中完成此操作。

【问题讨论】:

    标签: javascript c# jquery


    【解决方案1】:

    使用OnClientClick 并将visible=false 更改为css 样式display:none;。请参考下面给出的解决方案:

    <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
        <ContentTemplate>
            <section>
                <div>
                    <label>
                        State</label>
                    <label class="select">
                        <asp:DropDownList ID="ddlState" runat="server" DataTextField="StateName" DataValueField="StateName">
                        </asp:DropDownList><i></i>
                    </label>
                </div>
            </section>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddlCountry" />
    
        </Triggers>
    </asp:UpdatePanel>
    
    <div>
        <label>
            Country</label>
        <label class="select">
            <asp:DropDownList ID="ddlCountry" runat="server" ToolTip="Select country" DataTextField="CountryName"
                DataValueField="CountryID" AutoPostBack="true" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged" OnClientClick="ShowCountryLabel();">
            </asp:DropDownList><i></i>
            <asp:Label ID="lblSelectCountryFirst" Text="Please Select Country" runat="server" ForeColor="Red" style="Display: none;"></asp:Label>
        </label>
    </div>
    </section>
    
    //Jquery Code
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>
    function ShowCountryLabel(){
        $("#lblSelectCountryFirst").show();
        __doPostBack('__Page', '');
    }
    </script>
    

    【讨论】:

      猜你喜欢
      • 2014-09-02
      • 1970-01-01
      • 2023-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多