Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm unable to find the control div in Code behind using .FindControl Is there any way to Access it in CodeBehind.


My Div is Located inside Repeater and i need to visible false the div

XML
<div id="divdlopt" runat="server" class="FileUploadDiv" style="display: none; width: 80%">
                                                                                                                            <asp:FileUpload ID="file" runat="server" size="10" CssClass="fileUploadControl" onchange="CopyMe(this, this.id)" />
                                                                                                                            <asp:TextBox ID="uploadFile" TabIndex="6" runat="server" Style="display: none;" CssClass="fileUploadTextbox"
                                                                                                                                Onclick="return img1(this,0)" onkeydown="return (event.keyCode == 9)" Width="7%"></asp:TextBox>
                                                                                                                        </div>
Posted
Updated 9-Jun-14 2:48am
v3
Comments
ZurdoDev 9-Jun-14 8:39am    
First, you have to set runat="server" on it. Second, you'll need to do it in one of the repeaters events.
Member 10869970 9-Jun-14 8:49am    
I'm not using any repeater Event. I'm just Using a For Loop
Naz_Firdouse 9-Jun-14 8:52am    
Use OnItemDataBound event of the repeater and inside that, you can access elements inside the repeater

Add runat="server" to your div and find it as you normally do. See this : How to address id'ed DIV from C#[^]
 
Share this answer
 
v3
please set runat="server" property of div.
 
Share this answer
 
you can find div using foreach loop.

foreach(RepeaterItem item in Repeater1.Items)
{
    HtmlGenericControl divdlopt= item.FindControl("divdlopt") as HtmlGenericControl;
}
 
Share this answer
 
Comments
Member 10869970 12-Jun-14 4:47am    
giving error
problem is you are using style="display: none;" have you try after removing these lines :-
style="display: none; width: 80%" ?
 
Share this answer
 
here's something I've implemented earlier

C#
public static Control RecFindControl(ControlCollection controles, string id)
{
    return RecFindControl(controles, id);
}


C#
private static Control pausa = null;
        public static Control RecFindControl(ControlCollection controles, string id)
        {
            foreach (Control ctrl in controles)
            {
                if (ctrl.ID == id)
                {
                    pausa = ctrl;
                    break;
                }
                else
                    RecFindControl(ctrl.Controls, id);
            }
            return pausa;
        }


that method goes to the deepest point of the controls you provide on the parameter (
C#
repeater.Controls
)

the Control you are looking for will be the "pausa".

sorry for the portuguese there and there, nothing you won't be able to read. Let me know.
 
Share this answer
 
You may use Panel. Panel is equal to Div in ASP.NET
 
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