[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?
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
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!!!
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!
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?
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.
Re: Changing image during page init
Yay! I figured it out myself :D
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