ASP.NET Class Files

D

Dessip

Hey,

Soryr to post this, but im getting amasingly confused from all of the
information out there, but i was wondering if some one could help me
with these 2 questions please, because they would imporve the quality
of my code alot.

1/ Is there any way that you can edit the <head> tag, because some of
my Class's have functions in there that are controled by JavaScript or
VBScript, (Address Book being a excellent example), and also i would
like to write my class's so that they can place a Link to a stylesheet
(If one exists) else jsut write a defualt style to the head (Thou i
guess a better way, might be to get it to look for the stylesheet, and
if it dont exists build a dummy one, and store it to the web server,
but still is it possible to write to the head please

2/ In a class is there any way that you can use the page that called
it without having to do something like this:

c#:
public ClassName(System.Web.UI.Page oPage)
{
oPage.Controls.Add(MyControl);
}

VB.NET:
Public Sub New(oPage as System.Web.UI.Page)
oPage.Controls.Add(MyControl)
End Sub

Instead i would like to do something like this:

C#:
public ClassName()
{
PageThatIsUsed.Controls.Add(MyControl);
}

VB.Net:
Public Sub New()
PageThatIsUsed.Controls.Add(MyControl)
End Sub

As you can see with that one, i wont ahve to get the user to specify
the page, it will default go to the page that is called.

Regards
CDove
 
D

Dessip

Hey Mark,

That is excellent thank you, but the problem is i dont inherit
System.Web.UI.Page, this is in a seperate CS File, sorry i forgot to
mention that, so when i put this. or Me. it only comes up with the
functions that are in the CS Files, and not the other Page Propertys
and Functions.

Thank you for information about the head, that is exactly what im
looking for, excellent thank you.

Regards
CDove
 
M

Mark Rae

That is excellent thank you, but the problem is i dont inherit
System.Web.UI.Page, this is in a seperate CS File, sorry i forgot to
mention that, so when i put this. or Me. it only comes up with the
functions that are in the CS Files, and not the other Page Propertys
and Functions.

Ah... You might be able to use Reflector for what you need - I'm not sure,
though... sorry...
Thank you for information about the head, that is exactly what im
looking for, excellent thank you.

No problem.
 
D

Dessip

Hey Mark,

Excellent thank you, after reading that thread i think i shall stick
with the way i was currently doing it, and allwoing the user to add a
refrence location for the controls that are being sent to the page,
Just would have been nicer for the user(future coder of my class) if
it automatically done it for them.

Regards
CDove
 
M

Mark Rae

Excellent thank you, after reading that thread i think i shall stick
with the way i was currently doing it, and allwoing the user to add a
refrence location for the controls that are being sent to the page,
Just would have been nicer for the user(future coder of my class) if
it automatically done it for them.

In fact, that article hints at why that actually wouldn't be a very good
idea... :)
 
M

Mike Hofer

Hey,

Soryr to post this, but im getting amasingly confused from all of the
information out there, but i was wondering if some one could help me
with these 2 questions please, because they would imporve the quality
of my code alot.

1/ Is there any way that you can edit the <head> tag, because some of
my Class's have functions in there that are controled by JavaScript or
VBScript, (Address Book being a excellent example), and also i would
like to write my class's so that they can place a Link to a stylesheet
(If one exists) else jsut write a defualt style to the head (Thou i
guess a better way, might be to get it to look for the stylesheet, and
if it dont exists build a dummy one, and store it to the web server,
but still is it possible to write to the head please

2/ In a class is there any way that you can use the page that called
it without having to do something like this:

c#:
public ClassName(System.Web.UI.Page oPage)
{
oPage.Controls.Add(MyControl);

}

VB.NET:
Public Sub New(oPage as System.Web.UI.Page)
oPage.Controls.Add(MyControl)
End Sub

Instead i would like to do something like this:

C#:
public ClassName()
{
PageThatIsUsed.Controls.Add(MyControl);

}

VB.Net:
Public Sub New()
PageThatIsUsed.Controls.Add(MyControl)
End Sub

As you can see with that one, i wont ahve to get the user to specify
the page, it will default go to the page that is called.

Regards
CDove

CDove,

If brevity is your issue (I got that impression, possibly
incorrectly), you can work around that with a With...End With block in
Visual Basic.

If it's not the issue, I'd recommend requiring the parameter anyway,
for a couple of reasons. The most important reason is that it creates
an explicit contract between the class and whoever instantiates it;
the class doesn't assume anything about the environment it's created
in, so that environment is free to change, and won't be broken if that
environment does change.

Further, anyone who reads the class's code will know *exactly* where
that value came from: it was provided. The class won't be *assuming*
anything about external details, or making potentially unsafe
decisions about the class that instantiated it.

Hope this helps!

Mike
 

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

Top