Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 21, 2012 12:34 PM by Mohammad Ali keerio
Jun 16, 2012 03:00 PM|LINK
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.Id , "ch"+i.ToString());
and this is how i call the control in my asp.net page
<CC:ServerControl1 ID="ServerControl" runat="server" />
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" />
this is how i use the Method
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;
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!
Jun 16, 2012 03:20 PM|LINK
Please check is your control added at page level or they are added within other controls. You may share your aspx and aspx.cs page for better understanding for us.
Jun 16, 2012 03:29 PM|LINK
<%@ Register Assembly="Controlls" Namespace="Controlls" TagPrefix="CC" %> do u mean for this???
i search in googel for this problem but the Findcontrol() methdon work only for servercontrols and i am not sure if checkbox is in runat="server" if not can u tell me how to add runat="server" in custum control
Jun 16, 2012 05:45 PM|LINK
Jun 21, 2012 10:26 AM|LINK
You are correct.
If you want to use the method Findcontrol to find the control in the code behind, you need to make sure that checkbox is in the runat="server".
In order to resolve your issue, could you share the complete code here or upload the project to skydrive? Then provide a link. I want to test it locally.
Jun 21, 2012 12:34 PM|LINK
Dear try this one
//If you have use the master page then try this here MainContent is ContentPalceHolder's ID
CheckBox =Master.FindControl("MainContent").FindControl("ch" + i) as CheckBox;
// IF you have use simple asp.net webform then try this
CheckBox = Page.FindControl("ch" + i) as CheckBox;
Hope this post will helps you