Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Current theme

Current theme

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
12 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paper67
    wrote on last edited by
    #1

    How to get the current theme from within a UserControl ?

    M 1 Reply Last reply
    0
    • P paper67

      How to get the current theme from within a UserControl ?

      M Offline
      M Offline
      michaelschmitt
      wrote on last edited by
      #2

      Hi, you mean like just the Name of the Pages' Theme? Within your UserControl, use

      this.Page.Theme

      to get or set the theme.

      P 1 Reply Last reply
      0
      • M michaelschmitt

        Hi, you mean like just the Name of the Pages' Theme? Within your UserControl, use

        this.Page.Theme

        to get or set the theme.

        P Offline
        P Offline
        paper67
        wrote on last edited by
        #3

        Hi, DeleteImageUrl is an exposed property of the user control.

        public string DeleteImageUrl
        {
        get { return m_strDeleteImageUrl; }
        set { m_strDeleteImageUrl = string.Format("~/App_Themes/{0}/{1}", this.Page.Theme, value); }
        }

        this.Page is null here. Why ?

        M 1 Reply Last reply
        0
        • P paper67

          Hi, DeleteImageUrl is an exposed property of the user control.

          public string DeleteImageUrl
          {
          get { return m_strDeleteImageUrl; }
          set { m_strDeleteImageUrl = string.Format("~/App_Themes/{0}/{1}", this.Page.Theme, value); }
          }

          this.Page is null here. Why ?

          M Offline
          M Offline
          michaelschmitt
          wrote on last edited by
          #4

          Has the UserControl been correctly added to a page before you set that property? When do you access the property? Is the control dynamically added or in markup?

          P 1 Reply Last reply
          0
          • M michaelschmitt

            Has the UserControl been correctly added to a page before you set that property? When do you access the property? Is the control dynamically added or in markup?

            P Offline
            P Offline
            paper67
            wrote on last edited by
            #5

            I placed the following line in a .skin file.

            <UC:MultiFileUpload runat="server" UpperLimit="10" Rows="5" ListItemHoverColor="#F2D76A" DeleteImageUrl="Img/Delete.png" />

            M 1 Reply Last reply
            0
            • P paper67

              I placed the following line in a .skin file.

              <UC:MultiFileUpload runat="server" UpperLimit="10" Rows="5" ListItemHoverColor="#F2D76A" DeleteImageUrl="Img/Delete.png" />

              M Offline
              M Offline
              michaelschmitt
              wrote on last edited by
              #6

              Ah, i see. You're working with skins and want the delete-image-url of your usercontrol to point to the correct image file of the current theme? Maybe the answer in this thread helps you?

              P 1 Reply Last reply
              0
              • M michaelschmitt

                Ah, i see. You're working with skins and want the delete-image-url of your usercontrol to point to the correct image file of the current theme? Maybe the answer in this thread helps you?

                P Offline
                P Offline
                paper67
                wrote on last edited by
                #7

                Correct. I followed your link, but I cann't see any answers. Basically what I do is the following: On the Page_Load event of the user control I inject javascript.

                ScriptManager.RegisterStartupScript(this, typeof(Page), "MultiFileUploadScript", GetJavaScript(), false);

                private string GetJavaScript()
                {
                StringBuilder JavaScript = new StringBuilder();
                :
                JavaScript.Append("var deleteImage = null;\n");
                if (m_strDeleteImageUrl != string.Empty)
                {
                JavaScript.Append("deleteImage = new Image();\n");
                JavaScript.AppendFormat("deleteImage.src = '{0}';\n", m_strDeleteImageUrl);
                JavaScript.AppendFormat("deleteImage.setAttribute('alt','{0}');\n", m_strDeleteText);
                }
                :
                return JavaScript.ToString();
                }

                How can I make m_strDeleteImageUrl point to the correct theme image ? tia

                M 1 Reply Last reply
                0
                • P paper67

                  Correct. I followed your link, but I cann't see any answers. Basically what I do is the following: On the Page_Load event of the user control I inject javascript.

                  ScriptManager.RegisterStartupScript(this, typeof(Page), "MultiFileUploadScript", GetJavaScript(), false);

                  private string GetJavaScript()
                  {
                  StringBuilder JavaScript = new StringBuilder();
                  :
                  JavaScript.Append("var deleteImage = null;\n");
                  if (m_strDeleteImageUrl != string.Empty)
                  {
                  JavaScript.Append("deleteImage = new Image();\n");
                  JavaScript.AppendFormat("deleteImage.src = '{0}';\n", m_strDeleteImageUrl);
                  JavaScript.AppendFormat("deleteImage.setAttribute('alt','{0}');\n", m_strDeleteText);
                  }
                  :
                  return JavaScript.ToString();
                  }

                  How can I make m_strDeleteImageUrl point to the correct theme image ? tia

                  M Offline
                  M Offline
                  michaelschmitt
                  wrote on last edited by
                  #8

                  Can't you just set the images' filename (or subpath below the themefolder) in the setter of the DeleteImageUrl property of your usercontrol (without the string.format(..theme...) part)? Then, in the GetJavaScript() Method (which you call during Page-Load), you can build the correct path including the theme-folder by using Page.Theme, as Page should not be null there.

                  P 1 Reply Last reply
                  0
                  • M michaelschmitt

                    Can't you just set the images' filename (or subpath below the themefolder) in the setter of the DeleteImageUrl property of your usercontrol (without the string.format(..theme...) part)? Then, in the GetJavaScript() Method (which you call during Page-Load), you can build the correct path including the theme-folder by using Page.Theme, as Page should not be null there.

                    P Offline
                    P Offline
                    paper67
                    wrote on last edited by
                    #9

                    I already tried that. Even in the JavaScript method Page.Theme is null. Could it have to do the way I set my theme. In web.config I do :

                    <pages styleSheetTheme="Sunset">
                    <controls>
                    :
                    </controls>
                    </pages>

                    tia

                    M P 2 Replies Last reply
                    0
                    • P paper67

                      I already tried that. Even in the JavaScript method Page.Theme is null. Could it have to do the way I set my theme. In web.config I do :

                      <pages styleSheetTheme="Sunset">
                      <controls>
                      :
                      </controls>
                      </pages>

                      tia

                      M Offline
                      M Offline
                      michaelschmitt
                      wrote on last edited by
                      #10

                      Oh yes, use Page.StyleSheetTheme instead. I really hope, the Page property of your control is not null..otherwise.. could you provide a sample project where it is not working? Cheers

                      1 Reply Last reply
                      0
                      • P paper67

                        I already tried that. Even in the JavaScript method Page.Theme is null. Could it have to do the way I set my theme. In web.config I do :

                        <pages styleSheetTheme="Sunset">
                        <controls>
                        :
                        </controls>
                        </pages>

                        tia

                        P Offline
                        P Offline
                        paper67
                        wrote on last edited by
                        #11

                        Found it. In my JavaScript method I got the path as follows :

                        string strImageThemePath = string.Format("{0}/App_Themes/{1}/{2}", Page.Request.ApplicationPath, Page.StyleSheetTheme, m_strDeleteImageUrl);

                        Thanks Michael for your help.

                        M 1 Reply Last reply
                        0
                        • P paper67

                          Found it. In my JavaScript method I got the path as follows :

                          string strImageThemePath = string.Format("{0}/App_Themes/{1}/{2}", Page.Request.ApplicationPath, Page.StyleSheetTheme, m_strDeleteImageUrl);

                          Thanks Michael for your help.

                          M Offline
                          M Offline
                          michaelschmitt
                          wrote on last edited by
                          #12

                          Oh thank god =) Not a problem - glad it finally worked

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups