![]() |
Access Page Properties from Within Custom Control?
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 |
RE: Access Page Properties from Within Custom Control?
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.) |
Re: Access Page Properties from Within Custom Control?
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 |
Re: Access Page Properties from Within Custom Control?
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.) |
Re: Access Page Properties from Within Custom Control?
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.) |
| All times are GMT. The time now is 11:30 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.