简体   繁体   English

FormView控件内的LoginView不在PostBack上进行数据绑定

[英]LoginView inside FormView control is not databinding on PostBack

I have a fairly simple form: 我有一个相当简单的表格:

<asp:FormView>
    <EditItemTemplate>
        <asp:LoginView>
            <RoleGroups>
                <asp:RoleGroup roles="Blah">
                    <ContentTemplate>
                        <!-- Databound Controls using Bind/Eval -->
                    </ContentTemplate>
                </asp:RoleGroup>
            </RoleGroups>
        </asp:LoginView>

        <!-- Databound Controls -->
    </EditItemTemplate>
</asp:FormView>

<asp:LinqDataSource OnUpdating="MyDataSource_Updating" />

I handle my LinqDataSource OnUpdating event and do some work handling some M:N fields. 我处理了LinqDataSource OnUpdating事件,并做了一些处理某些M:N字段的工作。 That all works. 一切正常。

However, once the update is finished (and I call e.Cancel = true), the LoginView control does not databind its children... so they are all blank. 但是,更新完成后(我将其称为e.Cancel = true),LoginView控件不会对其子项进行数据绑定...因此它们全部为空。 The FormView's viewstate is still fine, as all the rest of the controls outside of the LoginView appear fine. FormView的viewstate仍然很好,因为LoginView之外的所有其他控件都很好。 I even handle the FormView_DataBound event and a Trace shows that the FormView is being databound on postback. 我什至处理FormView_DataBound事件,并且Trace显示FormView在回发时被数据绑定。

Why then is the LoginView not keeping its ViewState/being databound? 为什么为什么LoginView不保持其ViewState /正在数据绑定? Here's a sample code snippet showing the flow: 这是显示流程的示例代码片段:

protected void MyDataSource_Updating(object s, LinqDataSourceUpdateEventArgs e)
{
    try 
    {
        Controller.DoSomething(newData);
        // attempts to databind again here fail
        // frmView.DataBind();
        // MyDataSource.DataBind();
        // LoginView.DataBind();
    }
    catch { // blah }
    finally 
    { 
        e.Cancel = true; 
    }
}

我通过恢复使用古老的方法来对所有数据进行数据绑定并更改LoginView来解决此问题。

Ok, i don't know if you need help at this time, but the contaiter that you need to catch is de FormItem, in this case you cant do this 好的,我目前不知道您是否需要帮助,但是您需要了解的内容是de FormItem,在这种情况下,您无法执行此操作

<%# DataBinder.Eval(((FormItem)Container.Parent).DataItem,"YOUR FIELD") %>

Sorry for my english. 对不起我的英语不好。

Bye. 再见

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM