带有模态弹出窗口的中继器



我正在开发一个评分表应用程序,我有一个带有单选按钮的中继器,当我检查收音机时,会出现一个弹出窗口。 它工作正常。 但问题是每当我检查另一行中的下一个收音机时,我都会收到重复的弹出窗口(一个用于新收音机,另一个用于上一个检查的收音机。 并且它发生在中继器的所有行上(如果我检查 20 个无线电20行它将同时显示20个弹出窗口)。 我需要无线电一直保持检查状态,但因为 Autopost 每次都会触发它们背后的代码。

该代码位于中继器的 PreRender 事件下,但有人建议我将其从中继器中删除。(顺便问一下,PreRender和ItemDataBound事件之间有什么区别?) 请帮忙。

这是我的代码:

namespace GAPP
{
    public partial class GRADE : System.Web.UI.Page
{
    bool rdchk = false;
    protected void Page_Load(object sender, EventArgs e)
    {
        //-----------to define an event handler for the RadioButton control inside a repeater----------
        this.rptr1.ItemDataBound += new RepeaterItemEventHandler(rptr1_ItemDataBound);

        if (IsPostBack)
        {

            for (int i = 0; i < this.rptr1.Items.Count; i++)
            {
                RadioButton RDB1 = rptr1.Items[i].FindControl("L1") as RadioButton;
                RadioButton RDB2 = rptr1.Items[i].FindControl("L2") as RadioButton;
                RadioButton RDB3 = rptr1.Items[i].FindControl("L3") as RadioButton;
                RadioButton RDB4 = rptr1.Items[i].FindControl("L4") as RadioButton;
                RadioButton RDB5 = rptr1.Items[i].FindControl("R1") as RadioButton;
                RadioButton RDB6 = rptr1.Items[i].FindControl("R2") as RadioButton;
                RadioButton RDB7 = rptr1.Items[i].FindControl("R3") as RadioButton;
                RadioButton RDB8 = rptr1.Items[i].FindControl("R4") as RadioButton;
                RDB1.AutoPostBack = true;
                RDB1.CheckedChanged += new EventHandler(RDBX1_CheckedChanged);
                RDB2.AutoPostBack = true;
                RDB2.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
                RDB3.AutoPostBack = false;
                RDB3.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
                RDB4.AutoPostBack = true;
                RDB4.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
                RDB5.AutoPostBack = true;
                RDB5.CheckedChanged += new EventHandler(RDBX1_CheckedChanged);
                RDB6.AutoPostBack = true;
                RDB6.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
                RDB7.AutoPostBack = false;
                RDB7.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
                RDB8.AutoPostBack = true;
                RDB8.CheckedChanged += new EventHandler(RDBX2_CheckedChanged);
            }
        }
    }
    //----------------------------end of define event-----------------------------------------

    private void RDBX1_CheckedChanged(Object sender, EventArgs e)
    {
        foreach (RepeaterItem item in rptr1.Items)
        {
            if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
            {
                AjaxControlToolkit.ModalPopupExtender mpex1 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender1");
                AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender2");
                Button bsr1 = (Button)item.FindControl("btn_saveRep1");
                Button bsr2 = (Button)item.FindControl("btn_saveRep2");
                Button bsr3 = (Button)item.FindControl("btn_repeat_cnxl1");
                Button bsr4 = (Button)item.FindControl("btn_repeat_cnxl2");
                RadioButton l1 = (RadioButton)item.FindControl("L1");
                RadioButton r1 = (RadioButton)item.FindControl("R1");
                if (l1.Checked && rdchk == false)
                {
                    bsr1.Visible = true;
                    bsr2.Visible = false;
                    bsr3.Visible = true;
                    bsr4.Visible = false;
                    mpex2.Show();
                }

                if (r1.Checked && rdchk == false)
                {
                    bsr1.Visible = false;
                    bsr2.Visible = true;
                    bsr3.Visible = false;
                    bsr4.Visible = true;
                    mpex2.Show();
                }

            }
        }
    }
    private void RDBX2_CheckedChanged(Object sender, EventArgs e)
    {
        foreach (RepeaterItem item in rptr1.Items)
        {
            if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
            {
                AjaxControlToolkit.ModalPopupExtender mpex1 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender1");
                AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender2");
                RadioButton l2 = (RadioButton)item.FindControl("L2");
                if (l2.Checked) mpex1.Show();

                RadioButton l4 = (RadioButton)item.FindControl("L4");
                if (l4.Checked) mpex1.Show();
                RadioButton r2 = (RadioButton)item.FindControl("R2");
                if (r2.Checked) mpex1.Show();

                RadioButton r4 = (RadioButton)item.FindControl("R4");
                if (r4.Checked) mpex1.Show();

            }
        }
    }


    protected void rptr1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {


    }
    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");
                Label lbl3 = (Label)item.FindControl("lbl_dg_repeat1");
                Label lbl4 = (Label)item.FindControl("lbl_dg_final1");
                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 mpex1 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender1");
                AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)item.FindControl("ModalPopupExtender2");
                Button bsr1 = (Button)item.FindControl("btn_saveRep1");
                Button bsr2 = (Button)item.FindControl("btn_saveRep2");
                Button bsr3 = (Button)item.FindControl("btn_repeat_cnxl1");
                Button bsr4 = (Button)item.FindControl("btn_repeat_cnxl2");


                //-----------------------------
                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;
                    l2.Checked = false;
                    l3.Checked = false;
                    l4.Checked = false;
                    r1.Checked = false;
                    r2.Checked = false;
                    r3.Checked = false;
                    r4.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";
                }
            }
        }
    }
    protected void rptr1_OnItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "saveRep1")
        {
            DropDownList ddl1 = (DropDownList)e.Item.FindControl("ddl_dg_repeat");
            RadioButtonList rbl1 = (RadioButtonList)e.Item.FindControl("radio_dg_final");
            Label lbl3 = (Label)e.Item.FindControl("lbl_dg_repeat1");
            Label lbl4 = (Label)e.Item.FindControl("lbl_dg_final1");
            AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("ModalPopupExtender2");
            lbl3.Text = ddl1.SelectedItem.Text;
            lbl4.Text = rbl1.SelectedItem.Text;
            mpex2.Hide();
            rdchk = true;


        }
        //------------------------------------------------------------

        if (e.CommandName == "saveRep2")
        {
            DropDownList ddl1 = (DropDownList)e.Item.FindControl("ddl_dg_repeat");
            RadioButtonList rbl1 = (RadioButtonList)e.Item.FindControl("radio_dg_final");
            Label lbl3 = (Label)e.Item.FindControl("lbl_dg_repeat2");
            Label lbl4 = (Label)e.Item.FindControl("lbl_dg_final2");
            RadioButton l1 = (RadioButton)e.Item.FindControl("L1");
            AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("ModalPopupExtender2");
            lbl3.Text = ddl1.SelectedItem.Text;
            lbl4.Text = rbl1.SelectedItem.Text;
            mpex2.Hide();
            rdchk = true;

        }
        //------------------------------------------------------------
        if (e.CommandName == "cnxlRepeat1")
        {
            AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("ModalPopupExtender2");
            RadioButton l1 = (RadioButton)e.Item.FindControl("L1");
            l1.Checked = false;
            mpex2.Hide();
        }

        //------------------------------------------------------------
        if (e.CommandName == "cnxlRepeat2")
        {
            AjaxControlToolkit.ModalPopupExtender mpex2 = (AjaxControlToolkit.ModalPopupExtender)e.Item.FindControl("ModalPopupExtender2");
            RadioButton r1 = (RadioButton)e.Item.FindControl("R1");
            r1.Checked = false;
            mpex2.Hide();
        }
        //------------------------------------------------------------
        if (e.CommandName == "rdown")
        {
            ListBox lbx1 = (ListBox)e.Item.FindControl("ListBox1");
            ListBox lbx2 = (ListBox)e.Item.FindControl("ListBox2");


            if (lbx1.SelectedIndex != -1)
            {
                lbx2.Items.Add(lbx1.SelectedItem);
                lbx1.Items.Remove(lbx1.SelectedItem);
                lbx2.SelectedIndex = -1;
            }
        }
        //------------------------------------------------------------

        if (e.CommandName == "rup")
        {
            ListBox lbx3 = (ListBox)e.Item.FindControl("ListBox1");
            ListBox lbx4 = (ListBox)e.Item.FindControl("ListBox2");

            if (lbx4.SelectedIndex != -1)
            {
                lbx3.Items.Add(lbx4.SelectedItem);
                lbx4.Items.Remove(lbx4.SelectedItem);
                lbx3.SelectedIndex = -1;
            }
        }

        //----------------------------------------------------------
        if (e.CommandName == "ddl3Databound")
        {
            DropDownList ddlr1 = (DropDownList)e.Item.FindControl("DropDownList3");
            ListBox lbx5 = (ListBox)e.Item.FindControl("ListBox1");
            lbx5.DataBind();
        }
        //----------------------------------------------------------
        if (e.CommandName == "plus")
        {
            Panel pnl1 = (Panel)e.Item.FindControl("pnlXtra");
            TextBox txtb1 = (TextBox)e.Item.FindControl("txtb_comment");
            ImageButton imgb1 = (ImageButton)e.Item.FindControl("imgBtn_xtraPlus");
            ImageButton imgb2 = (ImageButton)e.Item.FindControl("imgBtn_xtraMin");
            Label lblx1 = (Label)e.Item.FindControl("label2");
            lblx1.Text = "after";
            imgb1.Visible = false;
            imgb2.Visible = true;
            pnl1.Visible = true;

        }
    }
}

}

PreRender 和 ItemDataBound 事件之间有什么区别?

预呈现

是与您的页面相关的东西(在这里,控件也有预呈现事件),而 ItemDataBound 与您的控件相关联,如中继器、网格等。

预呈现在页面事件生命周期结束时调用 asp.net 就在页面在客户端浏览器上呈现之前。

ItemDataBound 在 Repeater/grid/datalist 控件中的项(foreach 项)进行数据绑定之后,但在页面上呈现之前发生

解决了,我有 2 个标签,当我检查收音机时会创建它们,我在 if 语句中使用了它们。因此,如果 2 个标签有文本,则不显示弹出窗口。

非常感谢。

相关内容

  • 没有找到相关文章

最新更新