获取在占位符中动态创建的用户控件中的Dropdownlist的Jquery值

时间:2022-12-07 22:02:45

I have a user control that contain a DropdownList. I use this user control in a web form using a placeholder. I create this user control dynamically I need to know, how can I get the selected value in the placeholder from the dropdownlist in JQuery when the dropdownlist change (Postback)? This is my user control:

我有一个包含DropdownList的用户控件。我使用占位符在Web表单中使用此用户控件。我动态创建这个用户控件我需要知道,当下拉列表更改(Postback)时,如何从JQuery的下拉列表中获取占位符中的选定值?这是我的用户控件:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="IVT_DropDownList.ascx.cs" Inherits="Evi.Sc.Web.Evi.IVT.Sublayouts.IVT_DropDownList" %>
<asp:DropDownList ID="DropDownList" runat="server" AutoPostBack="True">
</asp:DropDownList>

This is the place holder:

这是占位符:

<asp:PlaceHolder ID="plhStatusClient" runat="server"></asp:PlaceHolder>

This is the codebehind:

这是代码隐藏:

IVT_DropDownList UC_StatusClients = (IVT_DropDownList)LoadControl("~/Evi/IVT/Sublayouts/IVT_DropDownList.ascx");

            IvtStatusClient ivtStatusClient = new IvtStatusClient();

            //Get the database to retrieve the information of the status
            var lstStatusClients = ivtStatusClient.Get_AllStatusClients();

            UC_StatusClients.DataSource = lstStatusClients;
            UC_StatusClients.InsertFirstRow = new ListItem("All", "0");
            plhStatusClient.Controls.Add(UC_StatusClients);

I’m trying with this , but doesn’t works.

我正在尝试这个,但不起作用。

$("#plhStatusClient").val()

2 个解决方案

#1


1  

ASP.NET renders ID's differently, try with .ClientID

ASP.NET以不同的方式呈现ID,尝试使用.ClientID

$("#<%= plhStatusClient.ClientID %>").val()

#2


0  

<asp:PlaceHolder ID="plhStatusClient" runat="server" clientID="test">
</asp:PlaceHolder> // use client id  here i give an idea to use client id

in jquery

在jquery

$("#test").val();

#1


1  

ASP.NET renders ID's differently, try with .ClientID

ASP.NET以不同的方式呈现ID,尝试使用.ClientID

$("#<%= plhStatusClient.ClientID %>").val()

#2


0  

<asp:PlaceHolder ID="plhStatusClient" runat="server" clientID="test">
</asp:PlaceHolder> // use client id  here i give an idea to use client id

in jquery

在jquery

$("#test").val();