0

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

    }
}
4

1 回答 1

1

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

于 2013-05-08T11:50:55.047 回答