Solved

Help with C# code and themes

Posted on 2006-11-20
6
817 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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