Solved

Help with C# code and themes

Posted on 2006-11-20
6
789 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:gogetsome
Comment Utility
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
Comment Utility
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
Comment Utility
Your Awesome! That did the trick. LOL, I'm tired of work too.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now