Access Page Properties from Within Custom Control?

M

Mark Olbert

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
 
M

MSFT

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.)
 
M

Mark Olbert

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
 
¥

¥xÆW·L³n§Þ³N³B¤ä´©³¡

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.)
 
M

MSFT

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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top