473,473 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Object Design

JJ
Is it possible if I create an object that I created to have a method
that would register a pagescriptblock for a aspx page? So I would use
Page.RegisterClientScriptBlock in the method being called and the
object would know that it is refering to the calling aspx page.
Thanks,

JJ

Feb 7 '06 #1
6 1161
not 100% clear on what ur asking. Are you asking if you can access the Page
instance from a class method? Yes, using HttpContext.Current.Handler

Page page = HttpContext.CurrentHandler as Page;
if (page == null)
{
throw new ApplicationException("This method can only be called from within
an ASP.NET request");
}
page.Register...
karl

--
http://www.openmymind.net/

"JJ" <jj****@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Is it possible if I create an object that I created to have a method
that would register a pagescriptblock for a aspx page? So I would use
Page.RegisterClientScriptBlock in the method being called and the
object would know that it is refering to the calling aspx page.
Thanks,

JJ

Feb 7 '06 #2
Hi,

JJ wrote:
Is it possible if I create an object that I created to have a method
that would register a pagescriptblock for a aspx page? So I would use
Page.RegisterClientScriptBlock in the method being called and the
object would know that it is refering to the calling aspx page.
Thanks,

JJ


I am not sure if it's what you mean, but...

If your object is a control, it has a this.Page property which refers to
the ASPX page the control is included on. So you can do

this.Page.Register...

If your object is not a control, and has no reference to the page,
nothing forbids you to do:

public void MyMethod( Page thePage )
{
thePage.Register...
}

Is that what you meant?
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 7 '06 #3
JJ
If I create a class library that has a document class that I created
and I call the class in an aspx page it is now an object of the
document class. Now when I call a method that is part of the object,
just as you guys have above I wanted to know if its possible to call
Page.RegisterClientScriptBlock and it would know to register it for
that given page. I see I would have to pass in the a reference to the
page in my method correct? Am I using the right terminology here in my
explanation?

Thanks,
JJ

Feb 7 '06 #4
You're still not being very clear...but I do believe either Laurent's or my
solution is what you are looking for.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"JJ" <jj****@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
If I create a class library that has a document class that I created
and I call the class in an aspx page it is now an object of the
document class. Now when I call a method that is part of the object,
just as you guys have above I wanted to know if its possible to call
Page.RegisterClientScriptBlock and it would know to register it for
that given page. I see I would have to pass in the a reference to the
page in my method correct? Am I using the right terminology here in my
explanation?

Thanks,
JJ

Feb 7 '06 #5
Hi,

JJ wrote:
If I create a class library that has a document class that I created
and I call the class in an aspx page it is now an object of the
document class. Now when I call a method that is part of the object,
just as you guys have above I wanted to know if its possible to call
Page.RegisterClientScriptBlock and it would know to register it for
that given page. I see I would have to pass in the a reference to the
page in my method correct? Am I using the right terminology here in my
explanation?

Thanks,
JJ


The thing is: You need a reference to the Page containing the object you
created. There are many ways to get a reference to the Page your control
is into (see Karl's and my proposals). Your design must plan a way to
get the Page's reference, one way or the other.

Let's say you're in the Page_Load event handler, and you do:

MyObject myObject = new MyObject();

With this code, your "MyObject" instance doesn't have any reference to
the Page class. This is a unidirectional composition in UML. If you want
to pass a reference from the Page to the MyObject, you need something like:

MyObject myObject = new MyObject( this );

This is then bidirectional, means that you can reach the MyObject from
the Page, and you can also reach the Page from the MyObject.

Is that clearer?

Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 7 '06 #6
JJ
Yes Thanks Guys

JJ

Feb 7 '06 #7

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

Similar topics

2
by: ggg | last post by:
I'm looking for a complete project/application done with heavy use of of object-oriented programming & design. Preferably something well documented and/or commented so that I can pick it apart...
1
by: Robert Hathaway | last post by:
COMP.OBJECT FAQ Version II Beta now Available http://www.objectfaq.com/oofaq2 ================================================== - Latest Important Information on Object Technology - What's New...
6
by: NewToDotNet | last post by:
I am getting "Object reference not set to an instance of an object. " when I attempt to open a C# windows service class in design view, although I was able to initially create the service and open...
9
by: Keith Rowe | last post by:
Hello, I am trying to reference a Shockwave Flash Object on a vb code behind page in an ASP.NET project and I receive the following error: Guid should contain 32 digits with 4 dashes...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
2
by: Jeff | last post by:
I'm getting an Object Reference error before I even run my app, and I'm not sure where to look to find the cause. I'd appreciate your help. When I open my Windows Application project, the...
4
by: Carl J. Van Arsdall | last post by:
It seems the more I come to learn about Python as a langauge and the way its used I've come across several discussions where people discuss how to do things using an OO model and then how to design...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
1
by: Allan Ebdrup | last post by:
I get the error: "Cannot create an object of type 'CustomWizard' from its string representation 'CustomWizard1' for the CustomWizard Property." when I view my custom server web control in...
7
by: joproulx | last post by:
Hi, I was wondering if there was a way with Reflection to find dynamically if an object was referencing indirectly another object. A simple example would be: Object1 | --Object2 |
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.