asp.net c#multiple PlaceHolders在页面上有多个动态按钮

时间:2016-01-29 16:04:39

标签: c# asp.net

我创建动态按钮并将独特的按钮添加到2个不同的占位符。 click事件正确添加到每个按钮,但按钮click事件未在第二个占位符上触发。如果我将按钮更改为只添加到1个占位符,它们都会正确触发。我可以改变一下来解决这个问题,但我很好奇为什么第二个占位符是一个问题。代码如下:

代码背后的代码:

                //Create Colour Button
                RadButton buttonColour = new RadButton();
                buttonColour.EnableEmbeddedBaseStylesheet = false;
                buttonColour.EnableEmbeddedSkins = false;
                buttonColour.CssClass = "VariationButtonsColour";
                buttonColour.BackColor = System.Drawing.Color.White;
                buttonColour.Height = new Unit(45);
                buttonColour.Click += new EventHandler(ColourClick);
                buttonColour.Text = Colour;
                buttonColour.ButtonType = RadButtonType.SkinnedButton;
                buttonColour.ID = dr["Colour"].ToString() ;
                buttonColour.PressedCssClass = "VariationButtonsColourActive";

                foreach (Control ctrl in phColourButtons.Controls)
                {
                    if (ctrl is RadButton)
                    {
                        RadButton button = (RadButton)ctrl;
                        if (buttonColour.ID == button.ID)
                        {
                            ColourExists = ColourExists + 1;
                        }
                    }
                }

                if (ColourExists == 0)
                {
                    phColourButtons.Controls.Add(buttonColour);
                    Label spacer = new Label();
                    spacer.Width = new Unit(15);
                    spacer.Text = "  ";

                    phColourButtons.Controls.Add(spacer);
                }


                //Create Size Button
                RadButton buttonSize = new RadButton();
                buttonSize.EnableEmbeddedBaseStylesheet = false;
                buttonSize.EnableEmbeddedSkins = false;
                buttonSize.CssClass = "VariationButtonsSize";
                buttonSize.BackColor = System.Drawing.Color.White;
                buttonSize.Height = new Unit(45);
                buttonSize.Click += new EventHandler(SizeClick);
                buttonSize.Text = Size;
                buttonSize.ButtonType = RadButtonType.SkinnedButton;
                buttonSize.ID = dr["Size"].ToString();
                buttonSize.PressedCssClass = "VariationButtonsSizeActive";


                foreach (Control ctrl in phSizeButtons.Controls)
                {
                    if (ctrl is RadButton)
                    {
                        RadButton button = (RadButton)ctrl;
                        if (buttonSize.ID == button.ID)
                        {
                            SizeExists = SizeExists + 1;
                        }
                    }
                }

                if (SizeExists == 0)
                {
                    phSizeButtons.Controls.Add(buttonSize);
                    Label spacer = new Label();
                    spacer.Width = new Unit(15);
                    spacer.Text = "  ";
                    phSizeButtons.Controls.Add(spacer);
                }

如果有人能够解释为什么第二个占位符不起作用会更好。

0 个答案:

没有答案