检查已更改的事件未触发

时间:2013-05-08 09:34:55

标签: c# asp.net checkbox

我试图触发复选框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);

    }
}

1 个答案:

答案 0 :(得分:1)

Het在复选框控件中尝试此属性EnableViewState="true"