我有一个转发器,里面有一个复选框。
<tr class="datarow">
<td style="display: none">
<asp:HiddenField runat="server" ID="hfPortalUserId" Value='<%# Eval("portalUserId") %>' />
</td>
<td>
<asp:TextBox ID="tbUserName" runat="server" Enabled="false" Text='<%# Eval("portalCommonName") %>' Width="98%"></asp:TextBox>
</td>
<td>
<asp:CheckBox ID="chkActive" Enabled="false" runat="server" Checked='<%# IsPortalUserActive((DateTime)Eval("portalUserInactive")) %>' />
</td>
<td>
<asp:CheckBox ID="chkEmployee" Enabled="false" runat="server" Checked='<%# IsEmployee((int)Eval("portalUserTypeId")) %>' />
</td>
<td class="checkadmin">
<asp:CheckBox ID="chkAdmin" Enabled="false" runat="server" Checked='<%# IsAdministrator((int)Eval("siteSecurityRoleId")) %>' CssClass="chkadmin" />
</td>
<td>
<asp:DropDownList ID="ddlUserClient" Enabled="false" runat="server" Width="98%" ></asp:DropDownList>
<asp:HiddenField runat="server" ID="hfClientId" Value='<%#Eval ("clientId") %>' />
</td>
<td>
<asp:TextBox ID="tbEmail" runat="server" Enabled="false" Text='<%# Eval("portalEmail") %>' Width="98%" AutoCompleteType="None"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="tbPassword" runat="server" Enabled="false" Width="98%" AutoCompleteType="None" ></asp:TextBox>
<asp:TextBoxWatermarkExtender ID="wmPass" runat="server" TargetControlID="tbPassword" WatermarkText="Enter new Password"></asp:TextBoxWatermarkExtender>
</td>
<td>
<asp:Panel ID="pnlControls" runat="server" Visible="true">
<asp:ImageButton ID="btnEdit" ImageUrl="~/Images/Management/EditDocument_20x20.png" runat="server" ToolTip="Update User" CommandName="edit" CausesValidation="false" />
<asp:ImageButton ID="btnDelete" ImageUrl="~/Images/Management/Delete_black_20x20.png" runat="server" CommandName="delete" ToolTip="Mark User Inactive" CausesValidation="false" OnClientClick="return confirm('Are you sure you would like to delete this user');" />
</asp:Panel>
</td>
</tr>
当渲染控件时,控件被禁用,单击编辑按钮时,将启用行的控件。我正在尝试使用JQuery选择器来捕获Admin复选框单击事件以及弹出和警报框。
这是JQuery代码
$("input[id^=BodyLeft_rptUsers_chkAdmin]").change(function () {
alert('Event Fired');
if ($(this).is(':checked')) {
alert('You are about to give administrator privileges. Are you sure?');
}
});
如果我使用IE Developer Tools并在页面渲染后运行此脚本,它可以正常工作,但除此之外事件不会触发,也没有警告框。
答案 0 :(得分:0)
将其包装在$(function(){ })
内,这将确保在jQuery尝试查找所需元素之前加载页面。
$(function(){
$(".chkadmin").click(function () {
alert('Event Fired');
if ($(this).is(':checked')) {
alert('You are about to give administrator privileges. Are you sure?');
}
});
});