The page Init swaps some controls if there is a special control defined
instead:
---
protected void Page_Init(object sender, EventArgs e)
{
int intPartner = System.Convert.ToInt32(Request["partner"]);
if (intPartner > 0)
{
CheckControlsForSwap(intPartner, Page.Controls);
}
}
protected void CheckControlsForSwap(int intPartner, ControlCollection
controlCollection)
{
foreach (Control c in controlCollection)
{
//Response.Write("c.GetType:" + c.GetType().ToString() + "<br>");
if (c.GetType().ToString().Substring(0, 13) == "ASP.controls_")
{
/* convert a string like "ASP.controls_default_dynamicload_ascx" to:
* "controls/partner/[partnerid]/dynamicload.ascx"
*/
string strControlPath = c.GetType().ToString();
//check that this is not already a partner specific control
if (strControlPath.IndexOf(intPartner.ToString()) == -1)
{
strControlPath = strControlPath.Replace("ASP.", "");
strControlPath = strControlPath.Replace("_ascx", ".ascx");
strControlPath = strControlPath.Replace("default", "partner/" +
intPartner.ToString());
strControlPath = strControlPath.Replace("_", "/");
//load partner control
Control partnerControl = null;
bool blnLoaded = true;
try
{
partnerControl = Page.LoadControl(strControlPath);
}
catch (System.Web.HttpException)
{
blnLoaded = false;
}
if (blnLoaded)
{
//we have loaded a partner specific control and want to swap it with
hte default control
int intControlIndex = controlCollection.IndexOf(c);
//remove the default control
controlCollection.Remove(c);
//add partner control
controlCollection.AddAt(intControlIndex, partnerControl);
//call CheckControlsForSwap on the same collection again to swap other
controls in this collection
CheckControlsForSwap(intPartner, controlCollection);
//return because the enumerater can't continue when we've added and
removed controls from the collection
return;
}
}
}
if (c.HasControls()) CheckControlsForSwap(intPartner, c.Controls);
}
}
---
This works fine when I run it directly in a page, but when using a maste
page the Request["partner"] is empty even though the master page contains a
dropdownlist with the ID "partner" that isn't empty.
Kind Regards,
Allan Ebdrup