Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net UserControl属性和WebPartsTemplate,值丢失_Asp.net_User Controls_Web Parts - Fatal编程技术网

Asp.net UserControl属性和WebPartsTemplate,值丢失

Asp.net UserControl属性和WebPartsTemplate,值丢失,asp.net,user-controls,web-parts,Asp.net,User Controls,Web Parts,我试图将UserControls添加到webparts CatalogZone,但当用户选择要添加到显示中的控件时,我分配给控件的属性值将丢失或不会保留到显示中。如果在WebPartZone中显式声明相同的控件定义,则属性值将保持不变。我仔细阅读了代码,发现当从CatalogZone选择并随后从personalization db加载控件时,我定义的值丢失/忘记/放弃。请看下面我的代码 TestPage.aspx TestControl.ascx.cs 控件只包含一个标签,我正在通过FontBo

我试图将UserControls添加到webparts CatalogZone,但当用户选择要添加到显示中的控件时,我分配给控件的属性值将丢失或不会保留到显示中。如果在WebPartZone中显式声明相同的控件定义,则属性值将保持不变。我仔细阅读了代码,发现当从CatalogZone选择并随后从personalization db加载控件时,我定义的值丢失/忘记/放弃。请看下面我的代码

TestPage.aspx

TestControl.ascx.cs 控件只包含一个标签,我正在通过FontBold属性设置字体粗体值

public partial class TestControl : System.Web.UI.UserControl
{           
    public bool FontBold { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (FontBold)
            lblText.Font.Bold = true;
    }


}

我现在没有机会检查,但在我看来,FoldBold属性应该标记为可个性化、可浏览的属性

public partial class WebPartTest : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        Page.InitComplete += new EventHandler(BindDdlListModes);
        ddlListModes.SelectedIndexChanged += new EventHandler(ddlListModes_SelectedIndexChanged);
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void BindDdlListModes(object sender, EventArgs e)
    {
        WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(Page);
        string browseModeName = WebPartManager.BrowseDisplayMode.Name;

        ddlListModes.Items.Clear();

        foreach (WebPartDisplayMode mode in wpm.SupportedDisplayModes)
        {
            if (mode.IsEnabled(wpm))
            {
                ListItem item = new ListItem(mode.Name);
                ddlListModes.Items.Add(item);
            }
        }

        int index = ddlListModes.Items.IndexOf(ddlListModes.Items.FindByText(wpm.DisplayMode.Name));
        ddlListModes.SelectedIndex = index;
    }

    protected void ddlListModes_SelectedIndexChanged(object sender, EventArgs e)
    {
        WebPartManager wpm = WebPartManager.GetCurrentWebPartManager(Page);
        WebPartDisplayMode displayMode = wpm.SupportedDisplayModes[ddlListModes.SelectedValue];

        if (displayMode != null)
            wpm.DisplayMode = displayMode;

    }
}
public partial class TestControl : System.Web.UI.UserControl
{           
    public bool FontBold { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (FontBold)
            lblText.Font.Bold = true;
    }


}