Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > StackOverFlowException When Recursing Page Controls

Thread Tools

StackOverFlowException When Recursing Page Controls

Posts: n/a
I'm trying to recurse the controls on a web page and insert some data
about the controls into a database but I get a StackOverflowException
before a counter I set for debugging purposes even increments one time.
Here's the button code:

Protected Sub btnGetCtrls_Click(ByVal sender As Object, ByVal e As
EventArgs) _
Handles btnGetCtrls.Click
Dim strFormID As String
ControlAdapter.Fill(ControlTable) 'Probably not necessary
strFormID = Page.Form.ID 'Gets the ASP form ID to use for each record
GetControlInfoRecurse(Page, strFormID)
End Sub

Here's the function code:

Public Sub GetControlInfoRecurse(ByVal oControl As
System.Web.UI.Control, _
ByVal sFrmID As String)
Dim oChildControl As Control
Dim sType As String
Dim strSEM As String
Dim l As Long 'For debugging

'We are only interested in certain control types
'so test for those
sType = oControl.GetType().ToString()
If sType = "checkbox" Or sType = "select-one" _
Or sType = "radio" Or sType = "textbox" Or sType = "text" _
ControlAdapter.InsertQuery(oControl.ID, sFrmID, _
Catch ex As Exception
strSEM = ex.Message
End Try
End If
l += l

For Each oChildControl In oControl.Controls
GetControlInfoRecurse(oControl, sFrmID)

End Sub

Eventually, I want to turn this into a user control so I can record the
relevant controls on each of several web pages in an application.
The logic seems straight forward enough: From the button, I initially
pass the Page to the recursive function. First things first, I ought to
get a DB record of the Page itself. I know this part works because I
tested it before I put the recursive part in. When I put the recursive
part in, however, I don't even get the Page DB record before the
StackOverflowException happens. This seems odd -- is VS anticipating
that there might be a stack overflow. In any event, the recursion seems
very straight forward. For each control in the Page.Controls
collection, call the recursion again. Where is this unbounded?

Reply With Quote
Posts: n/a
Solved the main issues here. First, had to put the recursive part in a
test for whether a control has any child controls:

If oControl.HasCongtrol then
'Recurse here
End If

But, that wasn't all. I'm at home now so I'll have to post proper
credit tomorrow when I find the article I got the information from. I
rewrote the button click to pass a ControlCollection to the sub rather
than a control, and rewrote the sub to handle it that way. If anybody's
interested, I'll post the rewritten code tomorrow along with the
proper attribution.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursing macro preprocessing? Henrik Goldman C++ 4 10-22-2006 05:25 AM
Recursing for Progress Bar Python 4 09-19-2006 04:53 AM
StackOverflowException after Page.Unload - how to debug? Lars-Erik Aabech ASP .Net 8 04-29-2005 03:15 AM
recursing through files in a folder Scott Carlson Python 3 10-01-2004 05:51 PM
Recursing code problem snowdy C Programming 19 09-02-2003 04:27 PM