动态生成控件ID返回为NULL [英] Dynamically generated Controls ID returned as NULL

查看:188
本文介绍了动态生成控件ID返回为NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够在Page_ preINIT()函数来创建动态控件。

如何获取控件及其ID

我的C#code创建DynamicControls之一

  VAR BTN =新WebForms.Button();
        btn.Text =+;
        btn.ID =Addmore;
        btn.Click + =新System.EventHandler(AddMoreSearchFields);

我使用的是一块低于code的找到被点击该控件ID。

 字符串eTarget = Request.Params [__ EVENTTARGET]的ToString()。** eTarget始终是NULL **保护无效Page_ preINIT(对象发件人,EventArgs的发送)
    {        如果(Page.IsPostBack)
        {
            createdynamiccontrols(dynamic_filter_table.Rows.Count);            字符串eTarget = Request.Params [__ EVENTTARGET]的ToString()。
            如果(eTarget ==)
            {
                createdynamiccontrols(dynamic_filter_table.Rows.Count);            }        }    }


解决方案

在哪里code,你确实添加按钮的页面?

此外,它可能会更容易,只是将按钮添加到页面中 - 不动态 - 并根据你的需要安排比能见度

也许你甚至添加的按钮,页面不会动态忘了设置 =服务器属性?

I am able to create dynamic controls in Page_PreInit() function.

'How to retrieve the control and its ID'

My C# code to create one of the 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.

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?

这篇关于动态生成控件ID返回为NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆