Click here to Skip to main content
16,017,857 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
C#
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();
}}


and this is how i call the control in my asp.net page
ASP.NET
<CC:ServerControl1 ID="ServerControl"  runat="server" />


this is how it looks in pagesoure
HTML
<input type="checkbox" id="ch0" id="ServerControl" />
<input type="checkbox" id="ch1" id="ServerControl" />
<input type="checkbox" id="ch2" id="ServerControl" />


this is how i use the Method FineControl(id)
C#
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++;
                }
            }
}

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!
Posted
Updated 16-Jun-12 3:38am
v2

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"??
 
Share this answer
 
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"  />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900