$(document).ready(function () {
$("#MainContent_ddlFieldName").on("change", function () {
var id = $(this).val();
var name = $(this + "option:selected").text();
$('#<%= lblValue.ClientID %>').text(name);
$('#<%= lblType.ClientID %>').text(id);
});
});
<asp:Label ID="lblValue" runat="server" Text="" Visible="true"></asp:Label>
<asp:Label ID="lblType" runat="server" Text="" Visible="true"></asp:Label>
protected void btnSearch_Click(object sender, EventArgs e)
{
string strValue = lblValue.Text;
string strType = lblType.Text;
}
I am incorporating JavaScript and Asp.Net to extract the dropdownlist value and place it into a label. Even though it displays the text on the label, when I trigger a button or event, it reverts back to its previous value which is ""
If anyone could offer assistance with this, it would be greatly appreciated.
Thank you!