How to find all controls in a web page

Posted by Sivaprasadadiraju under ASP.NET on 12/20/2010 | Points: 10 | Views : 6598 | Status : [Member] | Replies : 4
Hi,
i have a text box and a button i am giving url of a web page in textbox . when clicking on button it should give all the controls in that url.

ex: when i am giving www.google.com how can i get buttons like "Google Search" and " I'm Feeling Lucky"

Regards,
Siva Prasad Adiraju

SIVA PRASAD ADIRAJU


Responses

Posted by: SheoNarayan on: 12/20/2010 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Look at this article http://www.dotnetfunda.com/articles/article1072-validating-domain-name-in-aspnet-.aspx and see how the other website content is being populated in the textarea.

That content is nothing but the html of the website whose url is mentioned in the textbox. In this way, if you enter google.com in the textbox you will get all the html of the google website.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Sivaprasadadiraju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 12/20/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi,

For information find all controls on Page, including child controls.shpw below link
http://dotnetguts.blogspot.com/2008/11/finding-all-controls-on-page-in-aspnet.html
http://odetocode.com/articles/116.aspx

Hope will help!

LP MER

Sivaprasadadiraju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 12/20/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

To Read the webpage and then to find out the control from that string.
Refer this links for to read a webpage...

http://www.csharp-station.com/HowTo/HttpWebFetch.aspx
http://www.aspnettutorials.com/tutorials/network/net-webpage-aspnet2-csharp.aspx

From that string to get the controls name for your way....try this...


Thanks,
T.Saravanan

Sivaprasadadiraju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/6/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Try this code

private void ListControlCollections()    

{
ArrayList controlList = new ArrayList();
AddControls(Page.Controls,controlList);
foreach (string str in controlList)
{
Response.Write(str + "<br/>");
}
Response.Write("Total Controls:" + controlList.Count);
}

private void AddControls(ControlCollection page,ArrayList controlList)
{
foreach (Control c in page)
{
if (c.ID != null)
{
controlList.Add(c.ID);
}
if(c.HasControls())
{
AddControls(c.Controls, controlList);
}
}
}


Thanks
Karthik
www.f5Debug.net

Sivaprasadadiraju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response