|
-
Mar 2nd, 2006, 11:40 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Changing image during page init
Using Visual Studio 2005 and ASP.NET 2.0
I have some images in my masterpage. Their source may change depending on a parameter in the URL. But I'm not sure whether to code this functionality during the pre-init of the masterpage, or the content page. Is the pre-init even the right time to change image sources?
Last edited by drpcken; Mar 7th, 2006 at 05:48 PM.
-
Mar 3rd, 2006, 10:08 AM
#2
Re: Changing image during page init
The pre-init SHOULD be right. I am assuming you will be creating a property in the master page's class, which you will then be assigning a value to from your content pages. Once the value has been assigned, preinit should be able to pickup this value and assign it to the image. If it is unable to look at this value, then do it in the load
-
Mar 7th, 2006, 11:35 AM
#3
Thread Starter
Fanatic Member
Re: Changing image during page init
Hey thanks for the reply. But I'm not quite sure how to create a property in the master page. Can you point me to a tutorial? I'm gonna search for it myself as well.
Thanks!!!
-
Mar 7th, 2006, 12:12 PM
#4
Thread Starter
Fanatic Member
Re: Changing image during page init
Ok I created my property in my master page like so:
VB Code:
Public Property Language() As String
Get
Return mLanguage
End Get
Set(ByVal value As String)
mLanguage = value
End Set
End Property
I tried creating a new instance of the property to an object but I can't get it to work. This property will be set via a parameter in the URL. Any help would be appreciated.
Thanks!
Last edited by drpcken; Mar 7th, 2006 at 03:22 PM.
-
Mar 7th, 2006, 03:58 PM
#5
Thread Starter
Fanatic Member
Re: Changing image during page init
Ok I'm starting to get the hang of this 
But if I'm using my contentpage to send the property value during the PreInit, which page event of the MasterPage do I handle the property reading and handling?
-
Mar 7th, 2006, 04:35 PM
#6
Thread Starter
Fanatic Member
Re: Changing image during page init
Ok here is my code from my MasterPage so far:
VB Code:
Partial Class Header
Inherits System.Web.UI.MasterPage
Private mLanguage As String
Private mDirective As String
Public Property Directive() As String
Get
Return mDirective
End Get
Set(ByVal value As String)
mDirective = value
End Set
End Property
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Select Case Me.Directive
Case "Products"
Products.ImageUrl = "images/new_header/Menu_Items/Products_On.jpg"
Case "About"
About.ImageUrl = "images/new_header/Menu_Items/AboutUs_On.jpg"
Case "Search"
Search.ImageUrl = "images/new_header/Menu_Items/Search_On.jpg"
Case "Employment"
Employment.ImageUrl = "images/new_header/Menu_Items/Employment_On.jpg"
Case "Contact"
Contact.ImageUrl = "images/new_header/Menu_Items/Contact_On.jpg"
End Select
End Sub
End Class
When my contentpage PreInit event fires, I would like it to change the Directive property of the MasterPage, but I'm not sure how to expose it from the contentpage.
-
Mar 7th, 2006, 05:47 PM
#7
Thread Starter
Fanatic Member
Re: Changing image during page init
Yay! I figured it out myself 
In my content page I added this:
VB Code:
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
CType(Master, Header).Directive = Request.QueryString("Directive")
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|