473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Recursion Method Problem

Hello,

I have a recursive method that looks through an ASP.Net page to find a
control by ID. My problem is after it finds the control, breaks from the
loop and returns the control, it goes to my recursive line (if
control.HasControls call the findctl method). I think the problem lies in
that the method returns a value. Is this the case? Any ideas?

Thanks

private Control FindCtl(Control oControl, string controlID)
{
Control control = new Control();
foreach (Control ctl in oControl.Controls)
{

if (ctl.ID == controlID)
{
control = ctl;
break;
}

if (ctl.HasControls())
{
FindCtl(ctl, controlName);
}
}
return control;
}
Dec 14 '06 #1
5 1107
Hi
Does the method findcontrol not do what you want?
Mark
Hello,

I have a recursive method that looks through an ASP.Net page to find a
control by ID. My problem is after it finds the control, breaks from the
loop and returns the control, it goes to my recursive line (if
control.HasControls call the findctl method). I think the problem lies in
that the method returns a value. Is this the case? Any ideas?

Thanks

private Control FindCtl(Control oControl, string controlID)
{
Control control = new Control();
foreach (Control ctl in oControl.Controls)
{

if (ctl.ID == controlID)
{
control = ctl;
break;
}

if (ctl.HasControls())
{
FindCtl(ctl, controlName);
}
}
return control;
}
Dec 14 '06 #2
Mark,

It finds the control however after it breaks out of the loop and then hits
return control line it goes up to FindCtl(ctl, controlName); line. I do not
know why this is happening?

Thanks

"mark carew" <ma*******@magicwanddept.com.auwrote in message
news:7p****************************@40tude.net...
Hi
Does the method findcontrol not do what you want?
Mark
>Hello,

I have a recursive method that looks through an ASP.Net page to find a
control by ID. My problem is after it finds the control, breaks from the
loop and returns the control, it goes to my recursive line (if
control.HasControls call the findctl method). I think the problem lies
in
that the method returns a value. Is this the case? Any ideas?

Thanks

private Control FindCtl(Control oControl, string controlID)
{
Control control = new Control();
foreach (Control ctl in oControl.Controls)
{

if (ctl.ID == controlID)
{
control = ctl;
break;
}

if (ctl.HasControls())
{
FindCtl(ctl, controlName);
}
}
return control;
}

Dec 14 '06 #3
I would change it to something like:

if (ctl.HasControls())
{
control = FindCtl(ctl, controlName);

if (control != null)
break;
}

"Mike" <mi***@mike.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
Hello,

I have a recursive method that looks through an ASP.Net page to find a
control by ID. My problem is after it finds the control, breaks from the
loop and returns the control, it goes to my recursive line (if
control.HasControls call the findctl method). I think the problem lies in
that the method returns a value. Is this the case? Any ideas?

Thanks

private Control FindCtl(Control oControl, string controlID)
{
Control control = new Control();
foreach (Control ctl in oControl.Controls)
{

if (ctl.ID == controlID)
{
control = ctl;
break;
}

if (ctl.HasControls())
{
FindCtl(ctl, controlName);
}
}
return control;
}

Dec 14 '06 #4
Thanks for the post. I changed my method to this:

public Control FindCtl(Control oControl, string controlID)
{
if (oControl.controlID == Id) return oControl;

foreach (Control Ctl in oControl.Controls)
{
Control FoundCtl = FindCtl(Ctl, controlID);
if (FoundCtl != null)
return FoundCtl;
}

return null;
}

"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:OS**************@TK2MSFTNGP02.phx.gbl...
>I would change it to something like:

if (ctl.HasControls())
{
control = FindCtl(ctl, controlName);

if (control != null)
break;
}

"Mike" <mi***@mike.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
>Hello,

I have a recursive method that looks through an ASP.Net page to find a
control by ID. My problem is after it finds the control, breaks from the
loop and returns the control, it goes to my recursive line (if
control.HasControls call the findctl method). I think the problem lies
in that the method returns a value. Is this the case? Any ideas?

Thanks

private Control FindCtl(Control oControl, string controlID)
{
Control control = new Control();
foreach (Control ctl in oControl.Controls)
{

if (ctl.ID == controlID)
{
control = ctl;
break;
}

if (ctl.HasControls())
{
FindCtl(ctl, controlName);
}
}
return control;
}


Dec 14 '06 #5


On 14 Dez., 20:24, "Mike" <m...@mike.comwrote:
Hello,

I have a recursive method that looks through an ASP.Net page to find a
control by ID. My problem is after it finds the control, breaks from the
loop and returns the control, it goes to my recursive line (if
control.HasControls call the findctl method). I think the problem lies in
that the method returns a value. Is this the case? Any ideas?

Thanks

private Control FindCtl(Control oControl, string controlID)
{
Control control = new Control();
foreach (Control ctl in oControl.Controls)
{

if (ctl.ID == controlID)
{
control = ctl;
break;

}if (ctl.HasControls())
{
FindCtl(ctl, controlName);

}
}
return control;
}

Hi,
try this(in VB.NET):
Private Function FindCtl(ByVal id As String, ByVal ctl As Control) As
Control
For Each cControl As Control In ctl.Controls
If cControl.ID.Equals(id) Then
Return cControl
End If
'looking for subcontrols
If cControl.HasControls Then
Dim ctrl As Control = FindCtl(id, cControl)
If cControl.ID.Equals(id) Then
Return cControl
End If
End If
Next
End Function

Dec 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Christian Hubinger | last post by:
Hi! I've implemented some DropDown list in ASP.NET that use Ajax to fetch the data from the server. The javascript is written to call cascading to the bottom most dropdown in order to update...
43
by: Lorenzo Villari | last post by:
I've tried to transform this into a not recursive version but without luck... #include <stdio.h> void countdown(int p) { int x;
75
by: Sathyaish | last post by:
Can every problem that has an iterative solution also be expressed in terms of a recursive solution? I tried one example, and am in the process of trying out more examples, increasing their...
18
by: MTD | last post by:
Hello all, I've been messing about for fun creating a trial division factorizing function and I'm naturally interested in optimising it as much as possible. I've been told that iteration in...
13
by: robert | last post by:
My code does recursion loops through a couple of functions. Due to problematic I/O input this leads sometimes to "endless" recursions and after expensive I/O to the Python recursion exception. What...
12
by: NOO Recursion | last post by:
Hi everyone! I am trying to write a program that will search a 12x12 for a thing called a "blob". A blob in the grid is made up of asterisks. A blob contains at least one asterisk. If an...
13
by: Mumia W. | last post by:
Hello all. I have a C++ program that can count the YOYOs that are in a grid of Y's and O's. For example, this Y O Y O O Y O Y O Y O O Y O Y Y O Y O Y O O Y O O Y Y O Y O
24
by: proctor | last post by:
hello, i have a small function which mimics binary counting. it runs fine as long as the input is not too long, but if i give it input longer than 8 characters it gives RuntimeError: maximum...
30
by: Jeff Bigham | last post by:
So, it appears that Javascript has a recursion limit of about 1000 levels on FF, maybe less/more on other browsers. Should such deep recursion then generally be avoided in Javascript?...
35
by: Muzammil | last post by:
int harmonic(int n) { if (n=1) { return 1; } else { return harmonic(n-1)+1/n; } } can any help me ??
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.