我有以下标记;
<fieldset style="width:40%;">
<legend> Site User Role Management</legend>
<asp:Label ID="lblSiteUserDDl" runat="server" AssociatedControlID="ddlSiteUsers"
Text="Manage the roles in which a user is registered by selecting the user from the dropdown list below."></asp:Label>
<asp:DropDownList ID="ddlSiteUsers" runat="server" CssClass="dropdowns" AutoPostBack="True" />
<br /><br />
<fieldset id="rolemanagement" style="width:80%;" runat="server" >
<legend></legend>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Label ID="lblCurrentRole" runat="server" CssClass="literaltext"></asp:Label><br />
<asp:Label ID="lblSiteUserRole" runat="server" CssClass="literaltext"></asp:Label><br />
<asp:DropDownList ID="ddlUserRoles" CssClass="dropdowns" runat="server"/><br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlSiteUsers" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
</fieldset>
</fieldset>
以及页面底部的以下脚本
<script>
$(document).ready(function() {
$('#<%= ddlSiteUsers.ClientID%> ').change(function () {
$(this).css({ 'color': 'black', 'font-size': '1.1em', 'font-weight': 'bold' });
var selecteditem = $(this).children("option:selected").text();
$('#<%= lblCurrentRole.ClientID%>').html("You selected the user: <span style='color:black;font-weight:bold;'>" + selecteditem + "</span>");
});
});
</script>
问题是第一个标签确实会正确更改,但在更新面板返回页面时会被删除。我已经尝试了通过谷歌找到的所有各种解决方案,但似乎都没有奏效。现在,带有两个标签和下拉列表的字段集始终可见,最终一旦我正确显示标签,该字段集将被隐藏,直到上方的下拉选择更改。