Solved

Help with C# code and themes

Posted on 2006-11-20
6
861 Views
Last Modified: 2012-05-05
Hello, Im learning about themes and how to change the Theme at runtime., I found this article and code (check out the download) which accomplished this task. The code is in C# and unfortuantly I'm still in VB.  Here is the  original artilcle and download page:
http://staff.develop.com/ballen/blog/CommentView.aspx?guid=09befce7-f48e-4555-891c-13818fd75a56

The sample application (the download) Uses a dropdown to select the theme from the getdirectorys of the app_themes. While this works great I would rather use image buttons instead of a dropdown.

Can someone help to modify the c# code below to accept the theme from image buttons green, blue and default?

Here is the script:

<script runat="server">

    protected void _button_Click(object sender, EventArgs e)
    {
        this.Profile.Theme = _themes.SelectedValue;
        Response.Redirect(Request.Path);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            foreach (string s in Directory.GetDirectories(Server.MapPath("~/App_Themes")))
            {
                _themes.Items.Add(Path.GetFileName(s));
            }
            _themes.SelectedIndex = -1;
            if (this.Page.Theme != null && this.Page.Theme.Length > 0)
            {
                _themes.Items.FindByText(this.Page.Theme).Selected = true;
            }
        }
    }
</script>

0
Comment
Question by:gogetsome
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 17981926
protected void _theme_button_Click(object sender, EventArgs e)
    {
        this.Profile.Theme = ((Button)sender).CommandName;
        Response.Redirect(Request.Path);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Button btnTemp;
            int i = 0;

            foreach (string s in Directory.GetDirectories(Server.MapPath("~/App_Themes")))
            {
                btnTemp = new Button();
                btnTemp.ID = "Button_" + i;
                btnTemp.CommandName = s;

                btnTemp.OnClick += _theme_button_Click;

               placeHolderObj.Controls.Add(btnTemp); //placeHolderObj needs to be added to your page

               i++;
            }
        }
    }
0
 
LVL 3

Accepted Solution

by:
rundkaas earned 500 total points
ID: 17981947
markup:  
<asp:ImageButton ID="GreenButton" runat="server" CommandArgument="Green" OnCommand="_button_Click" />
<asp:ImageButton ID="BlueButton" runat="server" CommandArgument="Blue" OnCommand="_button_Click" />

codebehind:
 protected void _button_Click(object sender, CommandEventArgs e)
    {
        this.Profile.Theme = e.CommandArgument;
        Response.Redirect(Request.Path);
    }
0
 

Author Comment

by:gogetsome
ID: 17982130
rundkaas, I'm geting the following errors:

Error      18      Cannot copy assembly 'PageEventsModule.dll' to file 'C:\Documents and Settings\sbaldridge\Desktop\DynamicThemeSample\DynamicThemeSample\WebSite\Bin\PageEventsModule.dll'.  Unable to add 'C:\Documents and Settings\sbaldridge\Desktop\DynamicThemeSample\DynamicThemeSample\PageEventsModule\obj\Debug\PageEventsModule.dll' to the Web.  Unable to add file 'Bin\PageEventsModule.dll'.  The requested operation cannot be performed on a file with a user-mapped section open.
      C:\...\WebSite\

Error      19      Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)      C:\Documents and Settings\sbaldridge\Desktop\DynamicThemeSample\DynamicThemeSample\WebSite\MasterPage.master      31      30      C:\...\WebSite\
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:gogetsome
ID: 17982171
strickdd,
I added a placeholder to the form but am getting these errors:

Error      18      Cannot copy assembly 'PageEventsModule.dll' to file 'C:\Documents and Settings\sbaldridge\Desktop\DynamicThemeSample\DynamicThemeSample\WebSite\Bin\PageEventsModule.dll'.  Unable to add 'C:\Documents and Settings\sbaldridge\Desktop\DynamicThemeSample\DynamicThemeSample\PageEventsModule\obj\Debug\PageEventsModule.dll' to the Web.  Unable to add file 'Bin\PageEventsModule.dll'.  The requested operation cannot be performed on a file with a user-mapped section open.
      C:\...\WebSite\

Error      19      Type 'ASP.masterpage_master' already defines a member called 'Page_Load' with the same parameter types      C:\Documents and Settings\sbaldridge\Desktop\DynamicThemeSample\DynamicThemeSample\WebSite\MasterPage.master      35      20      C:\...\WebSite\
0
 
LVL 3

Expert Comment

by:rundkaas
ID: 17982228
your right, a cast is nessisary (string)e.CommandArgument;

sorry about that, it's late here, and I'm tired from work.
0
 

Author Comment

by:gogetsome
ID: 17982552
Your Awesome! That did the trick. LOL, I'm tired of work too.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question