チェックボックスの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);
}
}