.NET - Render User Control Logo on Postback

I've got a vb.net page that has a company dropdown which causes a postback, and I'm wanting to change the logo at the top of the page with the logo of the selected company. The header bar which has the logo in it is in a user control called Nav.ascx. Due to the order of elements loading on the page, I'm not finding a good way to display the logo in the header unless the user reloads the page or navigates to another page. If I try to reset the logo in the dropdown.SelectedIndesChanged event, that's not working. Any ideas how best to accomplish this?
tablaFreakAsked:
Who is Participating?
 
Ryan ChongCommented:
let's say in your User Control you got the image control:

<asp:Image ID="Image1" runat="server" />

Open in new window


and you wish it to reflect with a logo image based on the selection of Dropdown list in Parent's Page, then in your Parent's Page (using same sample), you got:

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
            <asp:ListItem Value=""></asp:ListItem>
            <asp:ListItem Value="logo1.png">Logo 1</asp:ListItem>
            <asp:ListItem Value="logo2.png">Logo 2</asp:ListItem>
            <asp:ListItem Value="logo3.png">Logo 3</asp:ListItem>
        </asp:DropDownList>

Open in new window


then in Parent's Page, add this at code behind:

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
        Dim image As Image = TryCast(WebUserControl2.FindControl("Image1"), Image)
        Dim label As Label = TryCast(WebUserControl2.FindControl("Label1"), Label)
        If DropDownList1.SelectedValue <> "" Then
            If image IsNot Nothing Then image.ImageUrl = "./images/" + DropDownList1.SelectedValue
            If label IsNot Nothing Then label.Text = "You have selected: " + DropDownList1.SelectedValue
        Else
            If image IsNot Nothing Then image.ImageUrl = ""
            If label IsNot Nothing Then label.Text = ""
        End If
    End Sub

Open in new window

0
 
Ryan ChongCommented:
is the trigger point from Parent's page or from the User Control?

meaning to say, is the dropdown from the Parent's page or from the User Control?

see if this article is useful for you?

ASP.NET Web Form User Control's Basic Interaction
https://www.experts-exchange.com/articles/31726/ASP-NET-Web-Form-User-Control's-Basic-Interaction.html
0
 
tablaFreakAuthor Commented:
Thanks, Ryan - Thanks for the article, I'll take a look. And the dropdown list is on the main page, as is the user control for the page header. I can reference the user control inside the Page Init event, where I'm setting the display user name and some user-defined links, but it seems at the page load event it's too late to change what gets rendered in the user control. Not sure what to do other than forcing a second postback, which could trouble the user...
Thanks,
Steve
0
 
tablaFreakAuthor Commented:
Looks like in the article, data is passed from the user control to the parent page. My case is the other way around - parent page to user control.
Thanks,
Steve
0
 
tablaFreakAuthor Commented:
Thanks, that did it!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.