473,394 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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
Nov 17 '05 #1
5 1961
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.)

Nov 17 '05 #2
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
Nov 17 '05 #3
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.)

Nov 17 '05 #4
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.)

Nov 17 '05 #5
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.)

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
1
by: Mark Olbert | last post by:
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...
3
by: Mikip | last post by:
Hi, I have some properties that are common to all pages so I have created a base class which every page inherits from. I now also want to use these properties within User Controls on the page....
6
by: William Parker | last post by:
I have a web control I made called header.ascx. It has its own properties and methods I defined. But I cannot figure out how to access this control from my code behind page. I can create the...
1
by: digitalego | last post by:
Sorry if the title is a little confusing... Here is the problem. I am working with a "default.aspx" page that uses a user control I made: ------------------------------ | default.aspx ...
5
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all...
3
by: Alex Maghen | last post by:
Hi. I'm a little confused about the code that resides in the code-behind of a MasterPage and the code that resides in the code-behind of the actual pages that USE that MasterPage. I'm noticing,...
0
by: dixonjm | last post by:
Hi There, I am looking for a little help with direction on how to do the above. Basically I have a sql database which contains a table of properties - this table contains a description col, a...
7
by: Andy B | last post by:
I have a class I am creating for data access. I need to access controls from inside the class that are on a particular page. How do I do this? or is creating an instance of the page class and using...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.