[英]Dynamically generated Controls ID returned as NULL
I am able to create dynamic controls in Page_PreInit() function. 我能够在Page_PreInit()函数中创建动态控件。
'How to retrieve the control and its ID' “如何检索控件及其ID”
My C# code to create one of the DynamicControls 我的C#代码创建了DynamicControls之一
var btn = new WebForms.Button();
btn.Text = "+";
btn.ID = "Addmore";
btn.Click += new System.EventHandler(AddMoreSearchFields);
I am using the below piece of code to find which controlid is clicked. 我正在使用下面的代码来查找单击哪个controlid。
string eTarget = Request.Params["__EVENTTARGET"].ToString();
**eTarget is always "" NULL**
protected void Page_PreInit(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
createdynamiccontrols(dynamic_filter_table.Rows.Count);
string eTarget = Request.Params["__EVENTTARGET"].ToString();
if (eTarget == "")
{
createdynamiccontrols(dynamic_filter_table.Rows.Count);
}
}
}
Where's the code where you actually add the button to the page? 您实际上将按钮添加到页面的代码在哪里?
Also, it would probably be easier to just add the button to the page - not dynamically - and than arrange visibility based on what you need. 另外,将按钮添加到页面(而不是动态添加)可能会比根据您的需要安排可见性更容易。
Maybe you even have added the button to the page not dynamically and forgot to set the runat="server"
attribute? 也许您甚至没有将按钮动态添加到页面中,却忘记了设置runat="server"
属性?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.