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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Usercontrol - on load can I tell what page is loading it?

Status
Not open for further replies.

DarwinIT

Programmer
Apr 25, 2008
142
US
I just want to know at load time what page is showing that usercontrol so I can set the class property in the usercontrol differently based on the loading module. I tried setting it with a public method but that does not affect the display since it's already loaded.
 
a better solution. is to expose a public property and set it from the page. this way the user control isn't concerned about what page it's used on.
Code:
public partial class MyControl : UserControl
{
   public string CssToSet 
   {
      get {return MyControl.CssClass;}
      set {MyControl.CssClass = value;}
   }
}
Code:
public class ThisPage : Page
{
   public void Page_Load(object sender, EventArg e)
   {
        SomeInstanceOfMyControl.CssToSet = "foo";
   }
}
Code:
public class ThatPage : Page
{
   public void Page_Load(object sender, EventArg e)
   {
        InstanceOfMyControl.CssToSet = "bar";
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top