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
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!
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.
Shuvo
If more posts give you useful answers, Please mark each post as "Answer".
<%@ 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
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.
Best wishes,
Please mark the replies as answers if they help or unmark if not.
Feedback to us
Nika2008
0 Points
2 Posts
HI Find control inside control
Jun 16, 2012 03:00 PM|LINK
hi i need help
<div class="pre-action-link" id="premain0" width="100%"></div>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
<div class="pre-action-link" id="premain1" width="100%"></div>and this is how i call the control in my asp.net page
<div class="pre-action-link" id="premain2" width="100%"></div>this is how it looks in pagesoure
<div class="pre-action-link" id="premain3" width="100%"></div>this is how i use the Method
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!
Shuvo Aymon
Contributor
4820 Points
1167 Posts
Re: HI Find control inside control
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.
If more posts give you useful answers, Please mark each post as "Answer".
Nika2008
0 Points
2 Posts
Re: HI Find control inside control
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
Shuvo Aymon
Contributor
4820 Points
1167 Posts
Re: HI Find control inside control
Jun 16, 2012 05:45 PM|LINK
If more posts give you useful answers, Please mark each post as "Answer".
Catherine Sh...
All-Star
23373 Points
2490 Posts
Microsoft
Re: HI Find control inside control
Jun 21, 2012 10:26 AM|LINK
Hi,
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.
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store
Mohammad Ali...
Member
322 Points
64 Posts
Re: HI Find control inside control
Jun 21, 2012 12:34 PM|LINK
Hi,
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;Please "Mark as Answer" if this post helps.