在控件中查找控件 [英] Find control inside control

查看:86
本文介绍了在控件中查找控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助

我需要使用FindControl(id);方法获取控件;
但在我的控件中是HTML,并且具有2-ID,因为他是自定义控件.

这就是我创建控件的方式

hi i need help

i need to get a control from with using method FindControl(id);
but in my control is in HTML and it have 2-ID because he is custom controll

this is how i create the control

protected override void Render(HtmlTextWriter writer)
      {
   for(int i = 0 ; i < 3; i++)
{
                writer.AddAttribute(HtmlTextWriterAttribute.Type, "checkbox");
                writer.AddAttribute(HtmlTextWriterAttribute.Id , "ch"+i.ToString());
                this.AddAttributesToRender(writer);
                writer.RenderBeginTag(HtmlTextWriterTag.Input);
                writer.RenderEndTag();
}}



这就是我在asp.net页面中调用控件的方式



and this is how i call the control in my asp.net page

<CC:ServerControl1 ID="ServerControl"  runat="server" />



这就是在pageoure中的外观



this is how it looks in pagesoure

<input type="checkbox" id="ch0" id="ServerControl" />
<input type="checkbox" id="ch1" id="ServerControl" />
<input type="checkbox" id="ch2" id="ServerControl" />



这就是我使用方法FineControl(id)



this is how i use the Method FineControl(id)

for (int i = 0; i < 3; i++)
        {

            CheckBox cb = this.FindControl("ch"+i.ToString()) as CheckBox;
            if (cb != null)
            {
                if (cb.Checked == true)
                {
                    ss[pom] = i;
                    pom++;
                }
            }
}


一直以来,finecontrol给我null永远不会给我我所需要的东西吗?
有人可以给我任何建议吗?
thnx寻求帮助,对我的英语不好对不起!


and all time the finecontrol give me null never dont give me that what i need?
can some one give me any sugestion how to do it???
thnx for help and sorry for my bad english!

推荐答案

如何将runat ="server"放在自定义控件上
我不能做这样的事情
writer.AddAttribute(HtmlTextWriterAttribute.runat,"server");

而且您无法在pagesoure中看到属性runat ="server"
您能建议我如何使用runat ="server"进行此复选框吗?
how can i put the runat="server" on custom controll
i cant do somethink like this
writer.AddAttribute(HtmlTextWriterAttribute.runat , "server");

and u cant see the attribut runat="server" in pagesoure
can u suggest me how to do the checkbox with runat="server"??


您需要在输入类型复选框中添加runat ="server"属性.由于它没有runat ="server",因此它将无法在后面的代码中找到控件ID.


You need to add runat="server" attribute in your input type checkbox. As it does not has runat="server", so it will not be able to find the control id in code behind.


<pre lang="HTML"><input type="checkbox" id="ch0" runat="server" />
<input type="checkbox" id="ch1" id="ServerControl" runat="server" />
<input type="checkbox" id="ch2"runat="server" id="ServerControl"  />


这篇关于在控件中查找控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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