Switch logo image with skin persisted cookie

7 posts, 0 answers
  1. gonewalkabout
    gonewalkabout avatar
    12 posts
    Member since:
    Oct 2006

    Posted 02 Feb 2011 Link to this post

    I'm fairly new to the skinning controls.
    I have a logo image (a .gif) on my master page. I need the image url to change to a 'white on black' image as the page is initially loaded based on the cookie that is saved. 
    It works fine in the code below if I select a skin from the chooser and I notice that the chooser value is being updated form the cookie properly but I cannot for the life of me find a way to 'trap' either the cookie vale or the chooser value on the initial master page load.

    Implementing the code below in the Master Page Load always seems to bring back an empty string.

    If RadSkinManager1.GetSkinChooser.SelectedValue = "Black" Then
                imgLogo.ImageUrl = "~/Styles/Images/RWLogoWhite.gif"
    Else
                imgLogo.ImageUrl = "~/Styles/Images/RWLogoBlack.gif"
    End If
    Can I get access to the cookie value as the page initiates? 
    I am fine with the built in skins and don't want to get involved with custom skins if possible ... please help.
  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 08 Feb 2011 Link to this post

    Hello gonewalkabout,

    Can you try getting the desired value from the RadSkinManager1.Skin property? Or try using the Text property of the RadSkinManager1.GetSkinChooser.

    Greetings,
    Iana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. gonewalkabout
    gonewalkabout avatar
    12 posts
    Member since:
    Oct 2006

    Posted 08 Feb 2011 Link to this post

    I have tried both of those solutions and neither return the required result.
    On the Page Load of the master page the RadSkinManager1.Skin returns the value set in the control or an empty string when the value is removed.
    The GetSkinChooser,Text returns an empty string regardless in the page.load event BUT show the last value set by the cookie properly once the page is rendered.
    Can I not read the cookie 'value' somehow? I have PersistenceMode="Cookie" and I see what look like values in the values set in Persistence Mode and Persistence Key but I can't figure out the syntax fro reading them or is that possible?

    If RadSkinManager1.Skin = "Black" Then
                imgLogo.ImageUrl = "~/Styles/Images/RWLogoWhite.gif"
            Else
                imgLogo.ImageUrl = "~/Styles/Images/RWLogoBlack.gif"
            End If
            
    If RadSkinManager1.GetSkinChooser.Text = "Black" Then
                imgLogo.ImageUrl = "~/Styles/Images/RWLogoWhite.gif"
            Else
                imgLogo.ImageUrl = "~/Styles/Images/RWLogoBlack.gif"
            End If

  5. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 09 Feb 2011 Link to this post

    Hello gonewalkabout,

    Can you try opening a formal support ticket and send us a runnable sample illustrating your scenario for further debugging? Or you can share a sample code for replicating the problem here. We will check it out and turn back to you with our findings.

    Best wishes,
    Iana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  6. gonewalkabout
    gonewalkabout avatar
    12 posts
    Member since:
    Oct 2006

    Posted 09 Feb 2011 Link to this post

    My code is below as requested.
    I have two logos "~/Styles/Images/RWLogoWhite.gif" and "~/Styles/Images/RWLogoBlack.gif" (Image: "imgLogo"). Basically they are just negatives of each other, one suitable for the Telerik Black skin and the other for all other (basically white or close to white) Telerik skins. I have the RadSkinManager set to PersistenceMode="Cookie"
    You will see, in bold, in my code behind, that I am attempting to trap for the skin value that has been saved in, I assume, a cookie and modify the  imgLogo.ImageUrl accordingly on the page load of the master page.
    Stepping through either of the methods does not return the value of the PersistenceMode="Cookie", yet once the page is rendered the skin chooser text value is correct.

    Thanks for the help

    MASTER PAGE FILE
    <%@ Master Language="VB" CodeFile="Default.master.vb" Inherits="_Default" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
         
    <head id="Head1" runat="server" >
        <title>Realty Web</title>
        <style type="text/css">
        html, body, form
        {
            height: 90%;
            margin: 5px;
            padding: 0px;
            overflow: scroll;
        }
        </style>
        <link href="Styles/styles.css" rel="stylesheet" type="text/css" />
    </head>
    <body >
        <form id="form1" runat="server" >
        
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    <Scripts>
    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
    <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
    </Scripts>
    </telerik:RadScriptManager>

        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
        <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="All" />

        <table style="width: 100%;">
            <tr>
                <td>
                     
     
                </td>
                <td>
                    
                </td>
                <td style="text-align: right">
                   
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                    <asp:Image ID="imgLogo" runat="server" Height="37px" 
                        ImageUrl="~/Styles/Images/RWLogoWhite.gif" Width="149px" />
    &nbsp;
                    <asp:Label ID="lWhichDB" runat="server"></asp:Label>
                    
                    <asp:HiddenField ID="mCurrentFile" runat="server" />
                    
                </td>
                <td style="text-align: right">
                    &nbsp;</td>
                <td style="text-align: right">
                     Skin&nbsp;&nbsp;
                     <telerik:RadSkinManager ID="RadSkinManager1" Runat="server"
                    ShowChooser="True" PersistenceMode="Cookie" >
                    </telerik:RadSkinManager>
                </td>
            </tr>
            <tr>
                <td>
                    <telerik:RadMenu ID="RadMenu1" runat="server">
                    </telerik:RadMenu> 
                    <telerik:RadMenu ID="RadMenu2" runat="server">
                    </telerik:RadMenu>
                </td>
                <td>
                    
                </td>
                <td style="text-align: right">
                    Logged in as ... <asp:LoginName ID="LoginName1" runat="server" 
                        BorderStyle="None" />  | 
                    <asp:LoginStatus ID="LoginStatus1" runat="server" 
                     LogoutPageUrl="~/Default.aspx" BorderStyle="None"/>
                </td>
            </tr>
        </table>
            <asp:ContentPlaceHolder id="Head" runat="server" > 
            </asp:ContentPlaceHolder>


        <hr />
            <asp:ContentPlaceHolder id="MainContent" runat="server">
            </asp:ContentPlaceHolder>
        </form>
    </body>
    </html>

    MASTER PAGE CODE BEHIND

    Imports System
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Configuration
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI.WebControls.LoginName
    Imports Telerik.Web.UI
    Imports UserManager

    Partial Class _Default
        Inherits System.Web.UI.MasterPage

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
            Dim dbConnection As New SqlConnection
            Dim m As String
            dbConnection.ConnectionString = ConfigurationManager.ConnectionStrings("con_walkaboutcanuck").ConnectionString
            Dim sqlQuery As New SqlCommand("SELECT DB_Name()", dbConnection)
            sqlQuery.CommandType = CommandType.Text
            Try
                dbConnection.Open()
                m = sqlQuery.ExecuteScalar
                If m Like "*_dev*" Then
                    lWhichDB.Text = " * YOU'RE ATTACHED TO TEST * "
                End If
                dbConnection.Close()
            Catch ex As Exception
            End Try

            If RadSkinManager1.Skin = "Black" Then
                imgLogo.ImageUrl = "~/Styles/Images/RWLogoWhite.gif"
            Else
                imgLogo.ImageUrl = "~/Styles/Images/RWLogoBlack.gif"
            End If

          
    If RadSkinManager1.GetSkinChooser.Text = "Black" Then
                imgLogo.ImageUrl = "~/Styles/Images/RWLogoWhite.gif"
            Else
                imgLogo.ImageUrl = "~/Styles/Images/RWLogoBlack.gif"
            End If


            BindToDataSet()

        End Sub


  7. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 14 Feb 2011 Link to this post

    Hi gonewalkabout,

    Try moving the code for setting the logo image url on Page_PreRender as in the attached page.
    Let me know if this works for you.

    Best wishes,
    Iana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  8. gonewalkabout
    gonewalkabout avatar
    12 posts
    Member since:
    Oct 2006

    Posted 14 Feb 2011 Link to this post

    That got it!
    Pretty dumb of me ... I know to try that solution but with the radskinshooser value showing up in the load event it never even occurred to me to try.
    Thanks for the help.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017