Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list all html/Page objects from codebehind

Status
Not open for further replies.

AntonioVino

Programmer
Sep 30, 2008
5
NL
Anyone an idea how to list ALL the html or pageobjects from codebehind.
i want to find controls with a tooptip.
I've got a recursive loop going through me.controls but that just does not get all controls

[tt]
Public adss As String = "| | | | | | | | | "
Public adder As Integer = 0
Public sb As String
Protected Sub GetAllObjects(ByVal ctrl As Object)
sb += Left(adss,(adder*2)+1)&CType(ctrl.id,String)&"<br/>"
Try
If ctrl.tooltip<>"" Then sb+="HIT-"&ctrl.tooltip&"<br/>"
Catch ex As Exception
End Try
adder += 1
For Each c In ctrl.Controls
If c.controls.count > 0 Then GetAllObjects(c)
Next
adder -= 1
End Sub
response.write(sb):response.end
[/tt]
 
The controls you loop through are only server controls, if you need to find all HTML elements which have that tag as well then you will probably need to use a regular expression on the generated HTML.

To get to the HTML, you will probably need to use a response filter or a httpModule.

Mark,

[URL unfurl="true"]http://lessthandot.com[/url] - Experts, Information, Ideas & Knowledge
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Website Design
[URL unfurl="true"]http://aspnetlibrary.com[/url] - An online resource for professional ASP.NET developers
 
@mark,
Thanks for the speedy answer.
Your remark that they were only servercontrols was one of my first thoughts too. But inspecting the output I found also normal html controls in the list but not all.
[tt]
Example Output:
|
| |
| |MainForm
| | |MainTable
| | | |TopRow
| | | | |TopLeft
| | | | | |MenuTable
| | | | | | |
| | | | |TopRight
| | | | | |Right
| | | | | | |Login
| | | | | | | |LabelInputMemberArrow
| | | | | | | |LabelInputPasswordArrow
| | | | | | |MyScore
| | | |MidRow
| | | | |MidLeft
| | | | | |Canvas
| | | |BottomRow
| | | | |Bottomleft
| | | | |BottomRight
[/tt]
The labels are defined as (showing some examples):
[tt]
<form id="MainForm" runat="server" style="float: left">
<asp:Table ID="MenuTable" runat="server">
<label id="LabelInputMemberArrow" runat="server" style="display: none;"><-</label>
<label id="LabelInputPasswordArrow" runat="server" style="display: none;"><-</label>
[/tt]
So the question refined:
1.Why these and not the others?
2.What code to use to overcome?
 
They are still classed as server controls as you have the runat="server" attribute. For all of those elements that don't have that, the server is unaware of them.

You'll have to parse the html using one of the methods I suggested above if you want to find any elements that the server is unaware of.

Mark,

[URL unfurl="true"]http://lessthandot.com[/url] - Experts, Information, Ideas & Knowledge
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Website Design
[URL unfurl="true"]http://aspnetlibrary.com[/url] - An online resource for professional ASP.NET developers
 
@mark,
OK but why isn't
[tt]
<asp:TextBox ID="InputMember" TextMode="SingleLine" Columns="15" runat="server" CausesValidation="true" AutoCompleteType="Email" AutoPostBack="true" ToolTip="Type your Emailaddress here"></asp:TextBox>
[/tt]
showing? it also has a runat="server"
 
this would be better done on the client using javascript, since that's the information you are parsing. jquery would make this pretty simple by searching for any element with a tooltip attribute.
Code:
$(function () {
   $(document).find("[tooltip]").do_something_with_jquery_array();
});
the syntax would look something like that. for more help ask in the jquery forum on google groups.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
@jason
I could do that in javascript also but I need it in codebehind and without a postback

So clientside won't work
Thanks anyway
 
I don't know why your textbox isn't showing up. You'll have to either step through it with the debugger to find out, or provide the .aspx and .vb files so that we can have a look.

Mark,

[URL unfurl="true"]http://lessthandot.com[/url] - Experts, Information, Ideas & Knowledge
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Website Design
[URL unfurl="true"]http://aspnetlibrary.com[/url] - An online resource for professional ASP.NET developers
 
Well I've found the problem.
there was a <asp:ContentPlaceHolder> with litteral text inbetween that caused the problem. After correcting it I could walk through the entire tree.

<asp:ContentPlaceHolder id="Log" runat="server">></asp:ContentPlaceHolder>

caused the problem.
@All: Thanks for the assistance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top