繁体   English   中英

带回发的转发器

[英]repeater with postback

我有一个中继器,每个项目都有一个复选框和单选按钮。

  • 选中该复选框时,将禁用该项目内的所有控件(带有自动回发功能)
  • 单选按钮一旦选中就会显示一个弹出窗口(也带有自动回发)。

情况是:如果在转发器的任何项目中选中了单选按钮,则当我选中复选框控件以禁用某个项目时,将显示弹出窗口。 在回发期间,选中的单选按钮将导致弹出窗口显示。

我该如何预防? 复选框应仅禁用不显示弹出窗口的项目。

我的密码

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void rptr1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {


            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Label lbl1 = (Label)e.Item.FindControl("lbl_dg_task");
                Label lbl2 = (Label)e.Item.FindControl("lbl_dg_seq");
                CheckBox chb = (CheckBox)e.Item.FindControl("chkb_NO");
                RadioButton l1 = (RadioButton)e.Item.FindControl("L1");
                RadioButton l2 = (RadioButton)e.Item.FindControl("L2");
                RadioButton l3 = (RadioButton)e.Item.FindControl("L3");
                RadioButton l4 = (RadioButton)e.Item.FindControl("L4");
                RadioButton r1 = (RadioButton)e.Item.FindControl("R1");
                RadioButton r2 = (RadioButton)e.Item.FindControl("R2");
                RadioButton r3 = (RadioButton)e.Item.FindControl("R3");
                RadioButton r4 = (RadioButton)e.Item.FindControl("R4");
                AjaxControlToolkit.ModalPopupExtender mpex = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("mpe1");

                if (l1.Checked)
                {
                    //pop.Enabled = true;
                    ModalPopupExtender1.Show();
                }


                if (chb.Checked == true)
                {

                    l1.Enabled = false;
                    l2.Enabled = false;
                    l3.Enabled = false;
                    l4.Enabled = false;
                    r1.Enabled = false;
                    r2.Enabled = false;
                    r3.Enabled = false;
                    r4.Enabled = false;
                    lbl1.CssClass = "grayedout";
                    lbl2.CssClass = "grayedout";


                }
                else
                {
                    l1.Enabled = true;
                    l2.Enabled = true;
                    l3.Enabled = true;
                    l4.Enabled = true;
                    r1.Enabled = true;
                    r2.Enabled = true;
                    r3.Enabled = true;
                    r4.Enabled = true;
                    lbl1.CssClass = "seq";
                    lbl2.CssClass = "task";


                }
            }


        }


    protected void rptr1_PreRender(object sender, EventArgs e)
    {

            foreach (RepeaterItem item in rptr1.Items)
            {
                if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
                {
                    CheckBox chb = (CheckBox)item.FindControl("chkb_NO");
                    Label lbl1 = (Label)item.FindControl("lbl_dg_task");
                    Label lbl2 = (Label)item.FindControl("lbl_dg_seq");
                    RadioButton l1 = (RadioButton)item.FindControl("L1");
                    RadioButton l2 = (RadioButton)item.FindControl("L2");
                    RadioButton l3 = (RadioButton)item.FindControl("L3");
                    RadioButton l4 = (RadioButton)item.FindControl("L4");
                    RadioButton r1 = (RadioButton)item.FindControl("R1");
                    RadioButton r2 = (RadioButton)item.FindControl("R2");
                    RadioButton r3 = (RadioButton)item.FindControl("R3");
                    RadioButton r4 = (RadioButton)item.FindControl("R4");
                    AjaxControlToolkit.ModalPopupExtender mpex = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender1");


                    if (chb.Checked == true)
                    {
                        l1.Enabled = false;
                        l2.Enabled = false;
                        l3.Enabled = false;
                        l4.Enabled = false;
                        r1.Enabled = false;
                        r2.Enabled = false;
                        r3.Enabled = false;
                        r4.Enabled = false;
                        l1.Checked = false;
                        lbl1.CssClass = "grayedout";
                        lbl2.CssClass = "grayedout";

                    }
                    else
                    {
                        l1.Enabled = true;
                        l2.Enabled = true;
                        l3.Enabled = true;
                        l4.Enabled = true;
                        r1.Enabled = true;
                        r2.Enabled = true;
                        r3.Enabled = true;
                        r4.Enabled = true;
                        lbl1.CssClass = "seq";
                        lbl2.CssClass = "task";


                    }

                    if (l1.Checked)
                    {

                        //pop.Enabled = true;
                        ModalPopupExtender1.Show();


                    }

                }
            }
        }

不要使用PreRender事件来决定是否显示弹出窗口,而应使用单选按钮的OnCheckedChanged事件来显示它。

l1.CheckedChanged = (sender, e) => { if (l1.Checked) ModalPopupExtender1.Show(); };

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM