Results 1 to 7 of 7

Thread: [RESOLVED] Changing image during page init

  1. #1

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Resolved [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.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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

  3. #3

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    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!!!

  4. #4

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Re: Changing image during page init

    Ok I created my property in my master page like so:

    VB Code:
    1. Public Property Language() As String
    2.         Get
    3.             Return mLanguage
    4.         End Get
    5.         Set(ByVal value As String)
    6.             mLanguage = value
    7.         End Set
    8.     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.

  5. #5

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    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?

  6. #6

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Re: Changing image during page init

    Ok here is my code from my MasterPage so far:

    VB Code:
    1. Partial Class Header
    2.     Inherits System.Web.UI.MasterPage
    3.  
    4.     Private mLanguage As String
    5.     Private mDirective As String
    6.  
    7.     Public Property Directive() As String
    8.         Get
    9.             Return mDirective
    10.         End Get
    11.         Set(ByVal value As String)
    12.             mDirective = value
    13.         End Set
    14.     End Property
    15.  
    16.     Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    17.         Select Case Me.Directive
    18.             Case "Products"
    19.                 Products.ImageUrl = "images/new_header/Menu_Items/Products_On.jpg"
    20.             Case "About"
    21.                 About.ImageUrl = "images/new_header/Menu_Items/AboutUs_On.jpg"
    22.             Case "Search"
    23.                 Search.ImageUrl = "images/new_header/Menu_Items/Search_On.jpg"
    24.             Case "Employment"
    25.                 Employment.ImageUrl = "images/new_header/Menu_Items/Employment_On.jpg"
    26.             Case "Contact"
    27.                 Contact.ImageUrl = "images/new_header/Menu_Items/Contact_On.jpg"
    28.         End Select
    29.  
    30.     End Sub
    31. 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.

  7. #7

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    Re: Changing image during page init

    Yay! I figured it out myself

    In my content page I added this:

    VB Code:
    1. Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
    2.  
    3.         CType(Master, Header).Directive = Request.QueryString("Directive")
    4.  
    5.     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
  •  



Click Here to Expand Forum to Full Width