1

我在 ASCX 文件中有以下中继器:

<asp:Repeater ID="repeater1" runat="server">
            <HeaderTemplate>
                <ul class="formList">
            </HeaderTemplate>
            <ItemTemplate>
                <li><a href="plugins/umbracocontour/editForm.aspx?guid=<%# ((Umbraco.Forms.Core.Form)Container.DataItem).Id %>"
                    class="form">
                    <%# ((Umbraco.Forms.Core.Form)Container.DataItem).Name %></a> <small><a href="plugins/umbracocontour/editForm.aspx?guid=<%# ((Umbraco.Forms.Core.Form)Container.DataItem).Id %>">
                        Open form designer</a> <a href="plugins/umbracocontour/editFormEntries.aspx?guid=<%# ((Umbraco.Forms.Core.Form)Container.DataItem).Id %>">
                            View entries</a> </small></li>
            </ItemTemplate>
            <FooterTemplate>
                </ul>
            </FooterTemplate>
        </asp:Repeater>

它通过名为的方法填充数据ShowAllForms()

private void ShowAllForms()
{
    using (var formStorage = new FormStorage())
    {
        var list = formStorage.GetAllForms(false).OrderBy(f => f.Name).Where(form => Security.HasAccessToForm(form.Id)).ToList();

        this.repeater1.DataSource = list;
        this.repeater1.DataBind();

        if (list.Count == 0)
        {
            this.paneBrowse.Visible = false;
        }
    }
}

和`搜索表单:

private void SearchForms()
{
    var forms =
        this.formRepository.GetFormByFreeText(this.txtFormSearch.Text).Where(form => Security.HasAccessToForm(form.Id)).
            ToList();

    this.repeater1.DataSource = forms;
    this.repeater1.DataBind(); 
}

ShowAllForms()Page_Load如果没有回发,则在“显示所有表单”按钮的单击事件中调用。SearchForms()在“搜索表单”按钮的回发中调用。

作为非管理员用户,当我查看表单列表时,我最初会看到一大堆表单。然后我通过它的名称搜索一个不应该返回任何项目的表单。到现在为止还挺好。然后我单击将执行的“显示所有表单”按钮ShowAllForms(),这就是首先显示所有表单的方法。

但是,当第二次调用时,ShowAllForms()不会在转发器中显示任何表单数据。为了澄清,我可以看到forms变量中返回了一些项目,所以集合不是空的,但是这些项目都没有出现在转发器中。

我对这里可能发生的事情感到困惑。

编辑:

页面的 OnLoad 事件:

protected void Page_Load(object sender, EventArgs e)
{ 
    if (!this.IsPostBack)
    {
        this.ShowAllForms();    
    }
}

初始化:

protected void Page_Init(object sender, EventArgs e)
{
    this.formRepository = TinyIoC.TinyIoCContainer.Current.Resolve<IFormRepository>();
}
4

1 回答 1

1

我相信问题出在这里:

    if (list.Count == 0)
    {
        this.paneBrowse.Visible = false;
    }

我看不到您paneBrowse再次将 's 可见性设置为 true 的位置。

一个快速的解决方法是:

    this.paneBrowse.Visible == (list.Count > 0);
于 2013-02-13T18:00:37.147 回答