Access Page Properties from Within Custom Control?

Discussion in 'ASP .Net' started by Mark Olbert, Oct 15, 2003.

  1. Mark Olbert

    Mark Olbert Guest

    I've written a custom control that relies heavily on LinkButton
    controls.

    LinkButton controls don't behave properly under Netscape, but there's
    a simple patch/fix that involves registering some javascript code onto
    any page that uses LinkButtons.

    I'd like to design the custom control itself to register that
    javascript code, but the only way I know how to register javascript
    code require a valid Page reference...and I can't seem to find what
    method or event gets called in the framework at a point where the Page
    is valid (i.e., not null).

    Can anyone advise me on whether it's possible for a control to
    "self-register" code on a page? I must be missing something obvious...

    - Mark
     
    Mark Olbert, Oct 15, 2003
    #1
    1. Advertising

  2. Mark Olbert

    MSFT Guest

    Hi Mark,

    If your custom control inherits from System.Web.UI.UserControl, it will has
    a property named "page", which returns a reference to the Page instance
    that contains the custom control. You can register the script with this
    Page instance.

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    MSFT, Oct 15, 2003
    #2
    1. Advertising

  3. Mark Olbert

    Mark Olbert Guest

    Luke,

    Sorry, I wasn't clear enough. I am aware of that Page property, but for all of the events/method
    calls I've looked into within the Custom Control framework, it's null when I access it (e.g., during
    the OnLoad() call).

    Put another way, what I need to know is at what stage of the life cycle of the control its Page
    property actually points at the page object.

    - Mark
     
    Mark Olbert, Oct 15, 2003
    #3
  4. Hi Mark,

    Here is the scenario I tested:

    I have a web application project including a web form and an web
    usercontrol (.ascx). I add following code in the usercontrol:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here

    Dim scriptString As String = "<script language=JavaScript> "
    scriptString += "alert('Welcome to Microsoft .NET') "
    scriptString += "</script>"


    Me.Page.RegisterClientScriptBlock("clientScript", scriptString)


    End Sub

    And then add this control to my webform. It worked well and the script was
    executed on client browser.

    Is there any difference with your situation?

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    ¥xÆW·L³n§Þ³N³B¤ä´©³¡, Oct 16, 2003
    #4
  5. Mark Olbert

    MSFT Guest

    Hello Mark,

    If my suggestion is not clear or you didn't think it can resolve the
    problem, please post your comments here. I will continue to follow up on
    this issue.

    Thanks,

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    MSFT, Oct 20, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski
    Replies:
    0
    Views:
    956
    Nathan Sokalski
    Oct 17, 2005
  2. Harlan Messinger
    Replies:
    0
    Views:
    389
    Harlan Messinger
    Feb 18, 2008
  3. Matt Sokol
    Replies:
    2
    Views:
    434
    Theo Tillotson
    Aug 7, 2003
  4. Nathan Sokalski
    Replies:
    0
    Views:
    229
    Nathan Sokalski
    Oct 17, 2005
  5. Nathan Sokalski
    Replies:
    0
    Views:
    246
    Nathan Sokalski
    Oct 17, 2005
Loading...

Share This Page