G
Guest
I want to create a utility function that will seach the current page for one
of my UserControls by it's type. So, let's say that I have a UserControl
whose class I defined as follows:
namespace MyUtils
{
public partial class SomeUserControl : System.Web.UI.UserControl
{
...
}
}
Now, in another class "SomeUtils" I want to be able to get a reference to a
control on the current page if it's of TYPE "SomeUserControl". I want to do
it by its TYPE rather than by it's ID.
But I'm having a few problems. Here's what I have in my class so far (which,
you'll note, is partof the same namespace "MyUtils" as the UserControl). My
problems are in comments in the code below...
namespace MyUtils
{
public class SomeUtils
{
public static void DoSomethingToCtl()
{
SomeUserControl C;
// ERROR ABOVE. Says Type unknown in scope even though
// this class and the UserControl are both in this same
namespace
Page Pg = HttpContext.Current.Handler as Page;
//Even assuming I could create a variable of type
//"SomeUserControl" above, from there, I don't know
//how to search the page for a control of that TYPE. ALSO,
//Do I have to search the Page ("Pg") AND the
//MasterPage ("Pg.Master")? Or does the Page also
//get me all of the controls of its MasterPage?
}
}
}
Help much appreciated!
Alex
of my UserControls by it's type. So, let's say that I have a UserControl
whose class I defined as follows:
namespace MyUtils
{
public partial class SomeUserControl : System.Web.UI.UserControl
{
...
}
}
Now, in another class "SomeUtils" I want to be able to get a reference to a
control on the current page if it's of TYPE "SomeUserControl". I want to do
it by its TYPE rather than by it's ID.
But I'm having a few problems. Here's what I have in my class so far (which,
you'll note, is partof the same namespace "MyUtils" as the UserControl). My
problems are in comments in the code below...
namespace MyUtils
{
public class SomeUtils
{
public static void DoSomethingToCtl()
{
SomeUserControl C;
// ERROR ABOVE. Says Type unknown in scope even though
// this class and the UserControl are both in this same
namespace
Page Pg = HttpContext.Current.Handler as Page;
//Even assuming I could create a variable of type
//"SomeUserControl" above, from there, I don't know
//how to search the page for a control of that TYPE. ALSO,
//Do I have to search the Page ("Pg") AND the
//MasterPage ("Pg.Master")? Or does the Page also
//get me all of the controls of its MasterPage?
}
}
}
Help much appreciated!
Alex