Home > Net >  Update Logo image of master.page from child page asp.net(vb)
Update Logo image of master.page from child page asp.net(vb)

Time:11-26

I am creating a child page by using Master page. I have logo, company name in header part of master page. I need to display in next page(child page of master) after login page. Next page will be showing logo and company name of login user. I pass the logo path and company name from child page to master. Labels are doing well but can't display logo. Can you tell me how can I solve this problem?

here is my master.aspx

<asp:Label ID="lblcmpname" runat="server" Text=""></asp:Label>
<asp:Image ID="imglogo" runat="server"  />

and master.vb

Public Sub SetImageUrl(ByVal url As String)
        imglogo.ImageUrl = url

    End Sub

child.aspx

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/master.Master" CodeBehind="child.aspx.vb" Inherits="project.child" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>

child.vb

Dim companyname As String = DirectCast(Session("companyname "), String)
Dim logopath As String = DirectCast(Session("~logos/Logo.jpg"), String)

Dim lblcmpname As Label = TryCast(Me.Master.FindControl("lblcmpname"), Label)
lblcmpname.Text = cmpname

Dim myImage As Image = CType(Master.FindControl("imglogo"), Image)
 If Not myImage Is Nothing Then
    myImage.ImageUrl = logopath
 End If

here, the display of logo.

logo display

CodePudding user response:

Why not just use the page load event of the master page, and have it check for session.

The master page load event ALWAYS fires when you navagte to a new child page. Thus right after your logon, then if ok, then set session for the correct logo.

Now, in page load event of master, you can check for if NO session, and use your logon logo (or no logo),

So, you could put this in site.master page load event:

    If Session("companyname") Is Nothing Then
        lblcmpname.Text = "Not yet logged on"
    Else
        lblcmpname.Text = Session("companyname")
    End If

    If Session("MyLogo") Is Nothing Then
        imglogo.ImageUrl = "~/Content/MyDefault.ppg"
    Else
        imglogo.ImageUrl = Session("MyLogo")
    End If

so, now right after logon, you can go:

Session("companyname") = "The correct company name goes here"
Session("MyLogo") = "path to correct logo goes here

' now navigate to Default.aspx, or whatever page with a master page.

So, I would make the assume that without Session() for company name, and without Session("MyLogo"), then the page load code of master can handle this probem.

Thus, when you logon, you set the correct company name into session("compname"), and you set the correct path into session("MyLogo").

If the session not been setup (which will be the case when they not yet logged in), then test in master pageload for no session values can shove in a default company name (or ""), or whatever.

So, just keep in mind that the master page on-load event fires when you navigate to ANY page that has a master page attached. T

  • Related