I have changed my base page OnPreInit to get the theme name, not the full control name from Globals.ThemesSelectorID since an ImageButton does not store Request.Form[id] like a drop down list. I found that Request.Form[id] stores the value what was selected in the drop down... is this correct?
Since Request.Form[id] is not available, I pass Globals.ThemesSelectorID = myControl.ID. This gives me the correct theme name that was clicked.
The problem is that I have to click an imagebutton twice before the theme changes. On the first click, a test label next to my imageButton updates to display the new theme name that was clicked. However, it is not until the next click that the theme actually gets updated!
Is there somthing different about setting this.theme = Request.Form[id] from myControl.ID (themeName)?
Why does the book code pass uniqueID to Globals.ThemesSelectorID, not ID? If I pass uniqueID the value looks like ctl00$ThemeSelector1$goldLabel instead of the theme name of goldLabel. I am guessing Request.Form[id] provides the theme name only where Globals.ThemesSelectorID provides the full control information like above.
Why woulld only passing the ID (theme name) and not using the full control name cause the page to take 2 clicks to change the theme?
Code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace RC.RPC_Group.UI
{
public class BasePage : System.Web.UI.Page
{
protected override void OnPreInit(EventArgs e)
{
string id = Globals.ThemesSelectorID;
if (id.Length > 0)
{
// if this is a postback caused by the theme selectors dropdownlist,
// retrieve the selected theme and unse it for the current page request
if (Page.IsPostBack)
{
this.Theme = id;
this.Session["CurrentTheme"] = this.Theme;
}
else
{
if (this.Session["CurrentTheme"] != null)
this.Theme = this.Session["CurrentTheme"].ToString();
}
base.OnPreInit(e);
}
}
}
}
Code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using RC.RPC_Group;
namespace RC.RPC_Group.UI.Controls
{
public partial class ThemeSelector : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
WebControl myControl = sender as WebControl;
if (myControl != null)
{
Label1.Text = myControl.ID;
Globals.ThemesSelectorID = myControl.ID;
}
}
}
}