locked
Which Aspx Page is using the User Control currently ? RRS feed

  • Question

  • User-785861467 posted

    Hi, I have an ascx user control that is used in several aspx pages. Inside the user control, how can I find which page is using the control currently ? I figured that if I can do this, then alot of my coding can be inside the user control such as enabling and disabling buttons. (not sure if it makes a difference or not, but all aspx pages are using a master page.)

    Any hints ? many thanks in advance.

    Friday, October 23, 2009 8:04 PM

Answers

  • User2130758966 posted

    If the buttons that you are enabling and disabling are inside the user control then perhaps the approach to take should be to set a public property up for your control. For example Mode="LotsOfButtonsEnabled".

    In the page_load event of the usercontrol you can check this value and then enable or disable your controls accordingly.

    Obviously you would come up with a better mame for your modes [:)]


    This walkthrough has a usercontrol which has a public property on it:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 23, 2009 9:03 PM

All replies

  • User2130758966 posted

    If the buttons that you are enabling and disabling are inside the user control then perhaps the approach to take should be to set a public property up for your control. For example Mode="LotsOfButtonsEnabled".

    In the page_load event of the usercontrol you can check this value and then enable or disable your controls accordingly.

    Obviously you would come up with a better mame for your modes [:)]


    This walkthrough has a usercontrol which has a public property on it:

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 23, 2009 9:03 PM
  • User-785861467 posted

    Thanks for the quick answer Harry.

    To make it clearer, I have 3 aspx pages: Setup.aspx, Formula.aspx and Design.aspx,  and the 3 pages are using cutomUserControl.ascx.

    What I need is, in the customUserControl Page_Load event, a string variable will be assigned either Setup, Formula or Design.

    This way, and based on this string variable, i can code a switch and enable disable some buttons in the User Control that is suitable

    for the current loaded page.

     

    Cheers mate.

    Friday, October 23, 2009 9:41 PM
  • User-785861467 posted

    Hi again,

    Sorry Harry, I was too sleepy last night, so i couldn't get what you said.

    This morning, I just used a hidden field in customUserControl.ascx, and exposed it with {Get, Set}.

    From the hosting page Page_Load event, I assigned the hidden field and build my switch on it.

    It worked fine.

     

    Many thanks Harry. Cheers. 

    Saturday, October 24, 2009 7:29 AM