我创建动态按钮,我正在尝试使用FindControll
来避免多个ID,我将ID分配给UpdatePanel的触发器,但这总是说是null,当我按下按钮并使循环创建按钮并将id(动态地)分配给触发器。这总是说是重复的
这是我正在使用的代码:
protected void DynamicButton()
{
//BAD TOOLS INTO THE LIST AND SHOW
List.ListUsers listsArea = new List.ListUsers();
List<Data.Area> Area = listsArea.AreaList();
List<Data.Area> ListOfEquiposNoOk = Area.Where(x => x.AREA == "ENG" && x.STANDBY == 1).ToList();
List<Button> BotonesBad = new List<Button>();
List<Data.Area> ListOfEquiposOk = Area.Where(x => x.AREA == "ENG" && x.STANDBY == 0).ToList();
List<Button> Botones = new List<Button>();
var TeamGood = ListOfEquiposOk.Select(x => x.TEAM).Distinct().ToList();
foreach (var team in TeamGood)
{
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
UpdatePanel Update = (UpdatePanel)Master.FindControl("BtnG_" + team);
Button newButtonGood = new Button();
Control controlGoodID = FindControl("BtnG_" + team;);
if (controlGoodID == null && controlGoodID == null)
{
newButtonGood.CommandName = "Btn" + team;
newButtonGood.Text = team;
newButtonGood.CommandArgument = "ENG";
newButtonGood.ID = "BtnG_" + team;
trigger.ControlID = newButtonGood.ID;
trigger.EventName = "Click";
UpdatePanel4.Triggers.Add(trigger);
newButtonGood.Click += new EventHandler(Button1_Click);
Good.Controls.Add(newButtonGood);
newButtonGood.CssClass = "btn-primary outline separate";
}
else
{
Botones = Good.Controls.OfType<Button>().ToList();
Botones.Add(newButtonGood);
}
}
}
这是我在动态按钮上输入的HTML,以及我在尝试将id分配给trigger
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="tools_info" role="dialog">
<div class="modal-dialog modal-sm" style="width: 450px">
<div class="modal-content">
<h2>  Tools information</h2>
<br />
<ul class="nav nav-tabs">
<li><a data-toggle="tab" href="#good">Good Condition</a></li>
<li><a data-toggle="tab" href="#bad">Bad Condition</a></li>
</ul>
<br />
<div id="good" class="tab-pane fade in active">
<asp:UpdatePanel runat="server" ID="UpdatePanel2">
<ContentTemplate>
<asp:Panel runat="server" ID="Good">
<asp:TextBox ID="TextBoxA1" runat="server" Visible="False"></asp:TextBox>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
</div>
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>