我在网页上使用的控件中有一个webpart。该网页使用母版页,MP中有一个内容持有者可以控制对齐/设计问题。一切都适用于此,但webpart控件。当我将webpart放入容器时,我失去了移动webparts的能力,但是一旦我将它移出容器,它就能正常工作。
的Default.aspx
/// <summary>
/// Set the selected item equal to the current display mode.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Page_PreRender(object sender, EventArgs e)
{
MyWebPartManager wpm = (MyWebPartManager)WebPartManager.GetCurrentWebPartManager(Page);
Control control = (Control)Master.FindControl("divReturnBack");
if (control != null)
{
control.Visible = true;
control.Controls.Add(DisplayModeMenul1);
}
}
displaymode.ascx
MyWebPartManager webPartManager;
public void Page_Init(object sender, EventArgs e)
{
Page.InitComplete += new EventHandler(InitComplete);
}
public void InitComplete(object sender, System.EventArgs e)
{
webPartManager = (MyWebPartManager)WebPartManager.GetCurrentWebPartManager(Page);
String browseModeName = WebPartManager.BrowseDisplayMode.Name;
foreach (WebPartDisplayMode mode in
webPartManager.SupportedDisplayModes)
{
String modeName = mode.Name;
if (mode.IsEnabled(webPartManager))
{
ListItem listItem = new ListItem(modeName, modeName);
ddlDisplayMode.Items.Add(listItem);
}
}
}
public void ddlDisplayMode_SelectedIndexChanged(object sender, EventArgs e)
{
String selectedMode = ddlDisplayMode.SelectedValue;
WebPartDisplayMode mode = webPartManager.SupportedDisplayModes[selectedMode];
if (mode != null)
{
webPartManager.DisplayMode = mode;
}
}
public void Page_PreRender(object sender, EventArgs e)
{
ListItemCollection items = ddlDisplayMode.Items;
int selectedIndex = items.IndexOf(items.FindByText(webPartManager.DisplayMode.Name));
ddlDisplayMode.SelectedIndex = selectedIndex;
}
答案 0 :(得分:0)
我将此代码移到了回发部分之外,现在工作正常。
// move to container in masterpage
Control control = (Control)Master.FindControl("divReturnBack");
if (control != null)
{
control.Visible = true;
control.Controls.Add(DisplayModeMenul1);
}