473,320 Members | 1,746 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,320 software developers and data experts.

Reference Page Controls From Class

How can I reference a page or user control's properties (such as viewstate)
and controls from another class?

TIA

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us

Nov 18 '05 #1
5 4017

You have to inherit the control to access things like the ViewState. For
example you want to extend the page class you would do:

public class ExtendedPage : System.Web.UI.Page
I'm not sure if that's what you're asking but that's what I understood from
your question
--
Abdellah Elamiri
..net Developer
Efficacy through simplicity
"Alphonse Giambrone" <NO**********@example.invalid> wrote in message
news:e2*************@TK2MSFTNGP09.phx.gbl...
How can I reference a page or user control's properties (such as viewstate) and controls from another class?

TIA

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us

Nov 18 '05 #2
Hi Alphonse,

From your description, you means how to reference a page or user control
from another class, does the class you mean a utilitiy class which want to
be isolated with the web related infos?

If so, I think there are two means you can choose:
1. Define a function in the certain class which contains a param the type
of which is "Page" or "UserControl" then, you can reference the certain
Page or UserControl's members: For example:
public class ...
public void processPage(Page page)
{
page.XXX. = xxxx;
}

public void processUserControl(UserControl uc)
{
uc.xxxx = xxx;
}
2. In ASP.NET web applicatoin the HttpContext.Current static member provide
the reference to the current processed Request's Context and if the
request's handler is a Page handler(or other classes derived from
System.Web.UI.Page), we can use the HttpContext.Current.Handler to get the
Current Page's reference ,such as:

public void processPage()
{
Page page = (Page)HttpContext.Current.Handler;
page.XXX = xxx;
}

In addtion, here are some former threads discussing on the similar
questions:

http://groups.google.com/groups?hl=e...readm=I5%24opc
HGEHA.616%40cpmsftngxa06.phx.gbl&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%
3DUTF-8%26oe%3DUTF-8%26q%3Dasp.net%2Bpage%2Bfrom%2Bclass%2B%2Bsteven% 2Bcheng

http://groups.google.com/groups?hl=e...readm=wAVBte%2
4CEHA.564%40cpmsftngxa06.phx.gbl&rnum=13&prev=/groups%3Fq%3D%2Bpage%2Bmember
%2Bsteven%2Bcheng%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26start%3D10%2
6sa%3DN

Hope also helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Nov 18 '05 #3
Thanks both for the replies.

It looks like you have nailed it for me Steven.

I should have mentioned that I am working in VB.NET. While I am familiar
with some of the c# syntax, I don't quite understand the following line:
Page page = (Page)HttpContext.Current.Handler;
What would be the equivalent in VB?

Also, is there any difference in performance using method 1 vs. method 2?

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:K9**************@cpmsftngxa06.phx.gbl...
Hi Alphonse,

From your description, you means how to reference a page or user control
from another class, does the class you mean a utilitiy class which want to
be isolated with the web related infos?

If so, I think there are two means you can choose:
1. Define a function in the certain class which contains a param the type
of which is "Page" or "UserControl" then, you can reference the certain
Page or UserControl's members: For example:
public class ...
public void processPage(Page page)
{
page.XXX. = xxxx;
}

public void processUserControl(UserControl uc)
{
uc.xxxx = xxx;
}
2. In ASP.NET web applicatoin the HttpContext.Current static member provide the reference to the current processed Request's Context and if the
request's handler is a Page handler(or other classes derived from
System.Web.UI.Page), we can use the HttpContext.Current.Handler to get the
Current Page's reference ,such as:

public void processPage()
{
Page page = (Page)HttpContext.Current.Handler;
page.XXX = xxx;
}

In addtion, here are some former threads discussing on the similar
questions:

http://groups.google.com/groups?hl=e...readm=I5%24opc HGEHA.616%40cpmsftngxa06.phx.gbl&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie% 3DUTF-8%26oe%3DUTF-8%26q%3Dasp.net%2Bpage%2Bfrom%2Bclass%2B%2Bsteven% 2Bcheng
http://groups.google.com/groups?hl=e...readm=wAVBte%2 4CEHA.564%40cpmsftngxa06.phx.gbl&rnum=13&prev=/groups%3Fq%3D%2Bpage%2Bmember %2Bsteven%2Bcheng%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26start%3D10%2 6sa%3DN

Hope also helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #4
Hi Alphonse,

I'm sorry for mistaken the langugage, here is the VB.NET version:
#1
Public Sub processPage(ByVal page As Page)
page.XXX = XXX
End Sub

#2
Public Sub processPage()
Dim page As Page = CType(HttpContext.Current.Handler, Page)
' in fact in VB.NET the following code is also ok
'Dim page As Page = HttpContext.Current.Handler
page.XXX = XXX;

End Sub

As my own oponion, both is ok and the I prefer the #1 better because it is
more convenient and more understandable. No critical concerns on
performacne both. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #5
Thanks, that should do it!

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:u1*************@cpmsftngxa06.phx.gbl...
Hi Alphonse,

I'm sorry for mistaken the langugage, here is the VB.NET version:
#1
Public Sub processPage(ByVal page As Page)
page.XXX = XXX
End Sub

#2
Public Sub processPage()
Dim page As Page = CType(HttpContext.Current.Handler, Page)
' in fact in VB.NET the following code is also ok
'Dim page As Page = HttpContext.Current.Handler
page.XXX = XXX;

End Sub

As my own oponion, both is ok and the I prefer the #1 better because it is
more convenient and more understandable. No critical concerns on
performacne both. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #6

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

Similar topics

1
by: Martine | last post by:
Hi there! I have a problem with programmatically adding user controls to my mobile webforms. If I load my usercontrol programmatically (in the Page_Load), the object is instantiated, I have...
4
by: Tomk | last post by:
I would like to make a routine that I can reuse on all my web forms to loop thru all webcontrols. However to do this I will need to pass a reference of the class that is associated with the form...
5
by: Alphonse Giambrone | last post by:
How can I reference a page or user control's properties (such as viewstate) and controls from another class? TIA -- Alphonse Giambrone Email: a-giam at customdatasolutions dot us
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
0
by: bminder | last post by:
Hello, Why would a web user control and master page not have access to a shared method in a library, when all regular pages do? For example, i have a library which has public class AAA. Public...
7
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb --...
8
by: PJ | last post by:
How can I get a reference to the master page class? It is defined as a partial class, but I cannot seem to type a variable to the name of the partial class? The compiler continually shows "The...
2
by: o0JoeCool0o | last post by:
I am trying to create a User Control, that will be a message box with input options if I call okconf.visible = true in the page load of the user control it works fine, but if i then try to call...
35
by: Chris | last post by:
Hi, I tried to create a class which must change the propety 'visible' of a <linktag in the masterpage into 'false' when the user is logged. But i get the error: "Object reference not set to an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.