Solved

Help with C# code and themes

Posted on 2006-11-20
6
827 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

792 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