用转发器动态控制

时间:2017-07-05 13:23:16

标签: c# asp.net repeater

我正在将动态按钮创建到转发器中,就像我之前在Page_Init中提出的问题所建议的那样我做了一些条件但是问题仍然存在,按钮不会触发指定的事件

这是第一个条件

public bool AssignClicked
        {
            get
            {
                return Convert.ToBoolean(ViewState["AssignClicked"]);
            }
            set
            {
                ViewState["AssignClicked"] = value;
            }
        }

然后这是当我点击按钮创建按钮变为true条件时的代码:

protected void DButton(object sender, EventArgs e)
    {
        AssignClicked = true;
        Page_Init(sender, e);
        Page_Load(sender, e);
    }

然后开始创建按钮

protected void Page_Init(object sender, EventArgs e)
        {
            if (AssignClicked)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "showAndHide();", true);

                Button Btn_clic = (Button)sender;
                var name = Btn_clic.Text;

                List.ListUsers listArea = new List.ListUsers();
                List<Data.Area> Area = listArea.AreaList();

                List<Data.Area> ListOfEquiposOk = Area.Where(x => x.AREA == name && x.STANDBY == 0).ToList();

                var TeamFCH = ListOfEquiposOk.Select(x => x.TEAM).Distinct().ToList();

                foreach (var team in TeamFCH)
                {
                    Button newButton = new Button();
                    newButton.CommandName = "Btn" + Convert.ToString(team);
                    newButton.ID = "Btn_" + Convert.ToString(team);
                    newButton.Text = team;
                    newButton.CommandArgument = name;

                    newButton.Click += new EventHandler(newButton_Click);

                    Repeater1.Controls.Add(newButton);

                    newButton.CssClass = "btn-primary outline separate";
                }
            }
        }

但是当我点击创建的按钮时,这不会做任何事情

0 个答案:

没有答案