已检查已更改的事件未触发
本文关键字:事件 检查 | 更新日期: 2023-09-27 18:12:41
我试图触发复选框checkedchanged事件,但似乎没有任何工作。我错过了一些东西在这里下面的代码。我认为我已经满足了所有必要的条件。那么到底哪里出了问题呢?
<asp:UpdatePanel ID="UpdatePanelApprove" runat="server" RenderMode="Inline" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" ID="LabelApproved" Font-Bold="true" ForeColor="Green"></asp:Label>
<asp:CheckBox runat="server" ID="CheckBoxApprove" Text="Approve?" OnCheckedChanged="CheckBoxApprove_CheckedChanged" AutoPostBack="True"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID ="CheckBoxApprove" EventName="CheckedChanged" />
</Triggers>
</asp:UpdatePanel>
编辑c#中的代码
protected void CheckBoxApprove_CheckedChanged(object sender, EventArgs e)
{
CheckBox CheckBoxApprove = (CheckBox)sender;
GridViewRow row = (GridViewRow)CheckBoxApprove.Parent.Parent.Parent;
HiddenField HiddenFieldAnswerId = (HiddenField)row.FindControl("HiddenFieldAnswerId");
HiddenField HiddenFieldExpertId = (HiddenField)row.FindControl("HiddenFieldExpertId");
Label LabelApproved = (Label)row.FindControl("LabelApproved");
UpdatePanel UpdatePanelApprove =(UpdatePanel) row.FindControl("UpdatePanelApprove");
int AnswerSubjectId = AnswerDataAccess.GetSubjectIdForAnswer(Convert.ToInt32(HiddenFieldAnswerId.Value));
if (!AnswerDataAccess.CheckAnswerApprovalStatus(Convert.ToInt32(HiddenFieldAnswerId.Value)))
{
if (AnswerDataAccess.ApproveAnswer(Convert.ToInt32(HiddenFieldAnswerId.Value)))
{
if (HiddenFieldExpertId.Value != Membership.GetUser().ProviderUserKey.ToString())
{
NotificationsAccess.InsertNotification(AnswerSubjectId, null, Convert.ToInt32(HiddenFieldAnswerId.Value), null, "Approved your answer", new Guid(Membership.GetUser().ProviderUserKey.ToString()), new Guid(HiddenFieldExpertId.Value));
}
LabelApproved.Text = "Approved";
}
}
else
{
if (AnswerDataAccess.DisapproveAnswer(Convert.ToInt32(HiddenFieldAnswerId.Value)))
{
LabelApproved.Text = "";
}
}
UpdatePanelApprove.Update();
}
新代码 protected void Page_Load(object sender, EventArgs e)
{
HtmlGenericControl Tabs = (HtmlGenericControl)this.Master.FindControl("divTabs");
Tabs.Style[HtmlTextWriterStyle.Display] = "block";
Tabs.Style["border"] = "1px solid #eee";
Tabs.InnerText = "some text";
Tabs.Style["font-size"] = "10px";
if(!IsPostBack )
{
DataTable UserS=ProfileDataAccess.GetUserS (Membership.GetUser().ProviderUserKey.ToString());
DropDownListS.DataSource=UserS;
DropDownListS.DataValueField ="SId";
DropDownListS.DataTextField="Sub";
DropDownListS.DataBind();
ListItem item= new ListItem("Select-s", "0");
item.Selected = true;
DropDownListS.Items.Add(item);
}
}
Het在复选框控件中试试EnableViewState="true"
属性