Click here to Skip to main content
15,905,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
how can i find control inside a div using tag name / type of control.

for example :

how can i get all the text boxes inside a div and apply some common style for all text boxes using C#?


i know div.findcontrol but that will search by control id only. can someone please help me ?
Posted

So, if you would like to find control by its tag, you need to loop through te collection of controls. Have a look here: How to: Access Controls by using the Controls Collection[^]
 
Share this answer
 
Comments
ravikhoda 25-Mar-14 3:24am    
i got unable to cast object when i tried the code as per above link.

here is a sample

foreach (HtmlInputText text in divcontaine.Controls)
{
if (text is HtmlInputText)

text.Style.Add("color", "red");
}

Error is : Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.HtmlControls.HtmlInputText'.
see this.. :)

CSS
input[type="text"] {
font-size: 8pt; 
font-family: Arial; 
}
 
Share this answer
 
v2
Comments
ravikhoda 25-Mar-14 3:03am    
i want to do this from c#

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