Solved

Help with C# code and themes

Posted on 2006-11-20
6
844 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…

749 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