473,661 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple asp.net programing question

Hello:

I have the following code that currently needs to go in every page.

QUESTION 1) Can Page_Preinit go somewhere else more global like Global.asax
so that I dont have to copy this code in every page

QUESTION 2) How can I externalize this code, ie, can I create a class ?...
some external code that would be located in one location only for ease of
maintenance that each page could call ? IF so, please describe in detail.

Thanks

Public Sub Page_PreInit(By Val sender As Object, ByVal e As EventArgs)
Dim page As Page
page = DirectCast(send er, Page)
If Session("Screen Resolution") = "" Then
Session("path") = Request.Path
Response.Redire ct("/Internals/Templates/detectscreen.as px")
End If
If Session("Screen Resolution") = "800" Then
page.MasterPage File = "/Internals/Templates/800MasterPage.m aster"
Else
page.MasterPage File = "/Internals/Templates/1024MasterPage. master"
End If
End Sub
Jan 27 '06 #1
5 1455
(a) You can use a shared base class for all your pages or a master page.

(b) You could just create a function, but I think the first solution is
better

public class utility
public sub shared SetMasterPage()
dim context as HttpContext = HttpContext.Cur rent;
dim page as Page = ctype(context .Handler, Page)
'write the rest of your code, Response/Session/Request can all be
accessed via context.Respons e, context.Session , context.Request
end sub
end class

call it via Utility.SetMast erPage() but again, I think if you can work out
how to do is ala (A), you'll be better off.

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

"Support" <Re************ ****@mail.oci.s tate.ga.us> wrote in message
news:uw******** ******@TK2MSFTN GP09.phx.gbl...
Hello:

I have the following code that currently needs to go in every page.

QUESTION 1) Can Page_Preinit go somewhere else more global like
Global.asax so that I dont have to copy this code in every page

QUESTION 2) How can I externalize this code, ie, can I create a class ?...
some external code that would be located in one location only for ease of
maintenance that each page could call ? IF so, please describe in detail.

Thanks

Public Sub Page_PreInit(By Val sender As Object, ByVal e As EventArgs)
Dim page As Page
page = DirectCast(send er, Page)
If Session("Screen Resolution") = "" Then
Session("path") = Request.Path
Response.Redire ct("/Internals/Templates/detectscreen.as px")
End If
If Session("Screen Resolution") = "800" Then
page.MasterPage File = "/Internals/Templates/800MasterPage.m aster"
Else
page.MasterPage File = "/Internals/Templates/1024MasterPage. master"
End If
End Sub

Jan 27 '06 #2
> QUESTION 1) Can Page_Preinit go somewhere else more global like
Global.asax so that I dont have to copy this code in every page
You can create a base class that inherits System.Web.UI.P age, which has this
method running in it, and inherit that class for all of your Pages.
QUESTION 2) How can I externalize this code, ie, can I create a class ?...
some external code that would be located in one location only for ease of
maintenance that each page could call ? IF so, please describe in detail.
This is the same as the answer to your first question. How you create the
class depends upon the coding model you're using, as well as the tools you
have.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Support" <Re************ ****@mail.oci.s tate.ga.us> wrote in message
news:uw******** ******@TK2MSFTN GP09.phx.gbl... Hello:

I have the following code that currently needs to go in every page.

QUESTION 1) Can Page_Preinit go somewhere else more global like
Global.asax so that I dont have to copy this code in every page

QUESTION 2) How can I externalize this code, ie, can I create a class ?...
some external code that would be located in one location only for ease of
maintenance that each page could call ? IF so, please describe in detail.

Thanks

Public Sub Page_PreInit(By Val sender As Object, ByVal e As EventArgs)
Dim page As Page
page = DirectCast(send er, Page)
If Session("Screen Resolution") = "" Then
Session("path") = Request.Path
Response.Redire ct("/Internals/Templates/detectscreen.as px")
End If
If Session("Screen Resolution") = "800" Then
page.MasterPage File = "/Internals/Templates/800MasterPage.m aster"
Else
page.MasterPage File = "/Internals/Templates/1024MasterPage. master"
End If
End Sub

Jan 27 '06 #3
Thanks Karl:
As i understand things - since I am choosing which master page to use based
upon screen resolution - the code could not be tied to the master page (I
think...) so this seems to lead me to having a shared base class for all my
pages ....
Any articles you know of on how to do that ?
Thanks
Terry

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:u4******** ******@TK2MSFTN GP11.phx.gbl...
(a) You can use a shared base class for all your pages or a master page.

(b) You could just create a function, but I think the first solution is
better

public class utility
public sub shared SetMasterPage()
dim context as HttpContext = HttpContext.Cur rent;
dim page as Page = ctype(context .Handler, Page)
'write the rest of your code, Response/Session/Request can all be
accessed via context.Respons e, context.Session , context.Request
end sub
end class

call it via Utility.SetMast erPage() but again, I think if you can work
out how to do is ala (A), you'll be better off.

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

"Support" <Re************ ****@mail.oci.s tate.ga.us> wrote in message
news:uw******** ******@TK2MSFTN GP09.phx.gbl...
Hello:

I have the following code that currently needs to go in every page.

QUESTION 1) Can Page_Preinit go somewhere else more global like
Global.asax so that I dont have to copy this code in every page

QUESTION 2) How can I externalize this code, ie, can I create a class
?... some external code that would be located in one location only for
ease of maintenance that each page could call ? IF so, please describe in
detail.

Thanks

Public Sub Page_PreInit(By Val sender As Object, ByVal e As EventArgs)
Dim page As Page
page = DirectCast(send er, Page)
If Session("Screen Resolution") = "" Then
Session("path") = Request.Path
Response.Redire ct("/Internals/Templates/detectscreen.as px")
End If
If Session("Screen Resolution") = "800" Then
page.MasterPage File = "/Internals/Templates/800MasterPage.m aster"
Else
page.MasterPage File = "/Internals/Templates/1024MasterPage. master"
End If
End Sub


Jan 27 '06 #4
Ur right about the first point, my bad for not paying closer attention :)

http://www.google.com/search?hl=en&l...ge&btnG=Search

relates to 1.1, but should be applicable in 2.0 all the same.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Support" <Re************ ****@mail.oci.s tate.ga.us> wrote in message
news:u0******** ******@TK2MSFTN GP10.phx.gbl...
Thanks Karl:
As i understand things - since I am choosing which master page to use
based upon screen resolution - the code could not be tied to the master
page (I think...) so this seems to lead me to having a shared base class
for all my pages ....
Any articles you know of on how to do that ?
Thanks
Terry

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:u4******** ******@TK2MSFTN GP11.phx.gbl...
(a) You can use a shared base class for all your pages or a master page.

(b) You could just create a function, but I think the first solution is
better

public class utility
public sub shared SetMasterPage()
dim context as HttpContext = HttpContext.Cur rent;
dim page as Page = ctype(context .Handler, Page)
'write the rest of your code, Response/Session/Request can all be
accessed via context.Respons e, context.Session , context.Request
end sub
end class

call it via Utility.SetMast erPage() but again, I think if you can work
out how to do is ala (A), you'll be better off.

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

"Support" <Re************ ****@mail.oci.s tate.ga.us> wrote in message
news:uw******** ******@TK2MSFTN GP09.phx.gbl...
Hello:

I have the following code that currently needs to go in every page.

QUESTION 1) Can Page_Preinit go somewhere else more global like
Global.asax so that I dont have to copy this code in every page

QUESTION 2) How can I externalize this code, ie, can I create a class
?... some external code that would be located in one location only for
ease of maintenance that each page could call ? IF so, please describe
in detail.

Thanks

Public Sub Page_PreInit(By Val sender As Object, ByVal e As EventArgs)
Dim page As Page
page = DirectCast(send er, Page)
If Session("Screen Resolution") = "" Then
Session("path") = Request.Path
Response.Redire ct("/Internals/Templates/detectscreen.as px")
End If
If Session("Screen Resolution") = "800" Then
page.MasterPage File = "/Internals/Templates/800MasterPage.m aster"
Else
page.MasterPage File = "/Internals/Templates/1024MasterPage. master"
End If
End Sub



Jan 27 '06 #5
Oopss..copied the wrong link:
http://aspnet.4guysfromrolla.com/articles/041305-1.aspx

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:e2******** *****@tk2msftng p13.phx.gbl...
Ur right about the first point, my bad for not paying closer attention :)

http://www.google.com/search?hl=en&l...ge&btnG=Search

relates to 1.1, but should be applicable in 2.0 all the same.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Support" <Re************ ****@mail.oci.s tate.ga.us> wrote in message
news:u0******** ******@TK2MSFTN GP10.phx.gbl...
Thanks Karl:
As i understand things - since I am choosing which master page to use
based upon screen resolution - the code could not be tied to the master
page (I think...) so this seems to lead me to having a shared base class
for all my pages ....
Any articles you know of on how to do that ?
Thanks
Terry

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:u4******** ******@TK2MSFTN GP11.phx.gbl...
(a) You can use a shared base class for all your pages or a master page.

(b) You could just create a function, but I think the first solution is
better

public class utility
public sub shared SetMasterPage()
dim context as HttpContext = HttpContext.Cur rent;
dim page as Page = ctype(context .Handler, Page)
'write the rest of your code, Response/Session/Request can all be
accessed via context.Respons e, context.Session , context.Request
end sub
end class

call it via Utility.SetMast erPage() but again, I think if you can work
out how to do is ala (A), you'll be better off.

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

"Support" <Re************ ****@mail.oci.s tate.ga.us> wrote in message
news:uw******** ******@TK2MSFTN GP09.phx.gbl...
Hello:

I have the following code that currently needs to go in every page.

QUESTION 1) Can Page_Preinit go somewhere else more global like
Global.asax so that I dont have to copy this code in every page

QUESTION 2) How can I externalize this code, ie, can I create a class
?... some external code that would be located in one location only for
ease of maintenance that each page could call ? IF so, please describe
in detail.

Thanks

Public Sub Page_PreInit(By Val sender As Object, ByVal e As EventArgs)
Dim page As Page
page = DirectCast(send er, Page)
If Session("Screen Resolution") = "" Then
Session("path") = Request.Path
Response.Redire ct("/Internals/Templates/detectscreen.as px")
End If
If Session("Screen Resolution") = "800" Then
page.MasterPage File = "/Internals/Templates/800MasterPage.m aster"
Else
page.MasterPage File = "/Internals/Templates/1024MasterPage. master"
End If
End Sub



Jan 27 '06 #6

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

Similar topics

2
4168
by: cyshao | last post by:
How to reset Router by programing? For some resean, we need usually reset our Router. Now, we have to Reset Router manually(shot down and reopen). Are there any method to control and reset Router by programing ? Thanks
1
914
by: joe | last post by:
I have never done any programing whatsoever and my boss has given a problem to fix in visual basic. I need to figure out how I can set up a field to sort multiple instances of a last name, by those people's first name. Anyone who could point me in the right direction it would be apprieciated (the data is saved through Access). Thanks, Joe
3
1180
by: dutche | last post by:
Hi, I'm new in Python and I'm learning with "Learning Python" oreilly's book which is very good written and explanatory. Now, that I know a bit of Python, I want to make some simple project, I thought something like a menu, just like "kxdocks" menu or something like that, with transparency and all with xml. But I dont know what things I have to know. PyGame is in it, right?
12
3585
by: Xah Lee | last post by:
Of Interest: Introduction to 3D Graphics Programing http://xahlee.org/3d/index.html Currently, this introduction introduces you to the graphics format of Mathematica, and two Java Applet utilities that allows you to view them with live rotation in a web browser. Also, it includes a introductory tutorial to POV-Ray.
6
2847
by: Sean | last post by:
Hi Everyone, My apologies for a somewhat dump question but I am really stuck. I have been working on this code for two days straight I am dont know what is wrong with it. when I run the code, All I get is Input: and the program quits. I also tried reading this online but I didn't quite get it. What is the diff between sin_addr and sin_addr.s_addr. My understanding is that the latter is the IP address of my machine where as the former is...
15
2785
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs. For example: f(3) f(3, )
2
1604
by: sengpg345 | last post by:
hi everybody. i have a project in colage for messanger but i haven't idea of socket programing in c#.net . so plz give me the guidence i socket programing. if u have row matirial or tutorial then give me.
4
4637
by: =?Utf-8?B?Y2FsZGVyYXJh?= | last post by:
Dear all, Until now I was programing for more that 6 years using VB.net simply because I come from that word and used to. Now I need to switch to C# simply because my customer want its project in that language. So now I am fighting with so simple thing like raising a simple event as follow, and have a complie error, with no damn idea what this compiler want. The code is as follow
2
1106
by: maamirj | last post by:
Hi, I am newly start prgraming from very beigning using .net c# 2005 can u help me the concepts of programing, oops from begining and how to start programing wih right techniques. thanks
0
8432
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8855
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8545
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2762
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 we have to send another system
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.