简体   繁体   English

如何调试一个FormView的Mode属性更改为Edit,但仍呈现与ReadOnly模式关联的视图的FormView?

[英]How to debug a FormView whose Mode property changes to Edit, but still renders the view associated with ReadOnly mode?

I am working with an ASP .NET application. 我正在使用ASP .NET应用程序。 It has a "Details.aspx" page where basically, the user can see or edit a data record. 它具有一个“ Details.aspx”页面,基本上,用户可以在其中查看或编辑数据记录。 The whole page is one giant FormView. 整个页面是一个巨大的FormView。 Suddenly, the Edit button stopped working - debugging confirmed that the FormView's FormView1_ModeChanging and FormView1_ModeChanged events get fired, and the mode gets changed to edit but in the browser, the normal readonly view stays visible, not the view from the EditItemTemplate. 突然,“编辑”按钮停止工作-调试确认FormView的FormView1_ModeChangingFormView1_ModeChanged事件被触发,并且模式已更改为可edit但在浏览器中,普通的只读视图保持可见,而不是EditItemTemplate的视图。

A diff to an older, working version shows that the only difference in the aspx file is that one custom control got removed from the ItemTemplate view (the one which gets loaded without a problem). 与较旧的工作版本的差异显示,aspx文件中的唯一区别是从ItemTemplate视图中删除了一个自定义控件(该控件自加载后没有问题)。 There are no changes in the code behind file. 文件后面的代码没有任何变化。 The EditItemTemplate of the FormView stays the same. FormView的EditItemTemplate保持不变。 The SqlDataSource to which the FormView is bound stays the same. FormView绑定到的SqlDataSource保持不变。 And its SelectQuery is very simple ( SELECT * FROM Embryonen ), so no changes to the database could have caused an SQL error which somehow prevents binding. 而且它的SelectQuery非常简单( SELECT * FROM Embryonen ),因此对数据库的任何更改都不会导致SQL错误,从而以某种方式阻止绑定。 (The Embryonen table still exists). (Embryonen表仍然存在)。 I have made changes to other parts of the application, but not to this page. 我对应用程序的其他部分进行了更改,但未对此页面进行过更改。 I tried setting a breakpoint into the Page_Load event of a control which might have stopped working after my other changes, but the breakpoint is never reached, I think the problem occurs before custom controls are loaded. 我尝试在控件的Page_Load事件中设置一个断点,该断点在我进行其他更改后可能已停止工作,但是从未达到断点,我认为问题是在加载自定义控件之前发生的。

I am out of ideas where to search for the problem. 我不知道在哪里寻找问题。 The developer who wrote the application also has no further ideas what could have happened. 编写应用程序的开发人员也没有进一步的想法。 What can I do? 我能做什么?

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div class="content">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <div id="BlackBorderColor">
                    <asp:FormView ID="FormView1" runat="server" DataKeyNames="Embryo_Id" DataSourceID="SqlDataSourceEmbryonen"
                        OnItemCommand="FormView1_ItemCommand" OnItemInserting="FormView1_ItemInserting"
                        OnItemUpdating="FormView1_ItemUpdating" OnItemDeleted="FormView1_ItemDeleted"
                        OnItemInserted="FormView1_ItemInserted" meta:resourcekey="FormView1Resource1"
                        OnItemDeleting="FormView1_ItemDeleting"
                        OnItemUpdated="FormView1_ItemUpdated" OnDataBound="FormView1_DataBound" OnModeChanged="FormView1_ModeChanged" OnModeChanging="FormView1_ModeChanging">
                        <EditItemTemplate>
                            <table class="formular" cellpadding="3" border="1" cellspacing="0">

(... lots of tablerows here ...) 

                           </table>

                        </EditItemTemplate>

                        <InsertItemTemplate> (...) </InsertItemTemplate>

                         <ItemTemplate>
                            <table cellpadding="3" border="1" cellspacing="0">

                             ( ... again lots of <tr> here ...) 
                             <tr> 
                                 <td class="formularBezeichner"> ... </td> 
                                 <td class="formular"> 

                                     <%--- Here, in the old version, is an .ascx control. In the current, not working, version, there is nothing. ---%> 
                                 </td>
                              </tr> 
                              (... and more table rows ...) 

                               <asp:Panel ID="PanelOwner" runat="server" Visible='<%# AllowEdit(Eval("InputUser"), Eval("Verantwortlicher_Email")) %>'
                                    meta:resourcekey="PanelOwnerResource2">
                                    <tr>
                                        <td colspan="2" class="ControlPanel">
                                            <asp:Button ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                                                Text="Bearbeiten" Width="120px" meta:resourcekey="EditButtonResource1" SkinID="Normal" />
                                            &nbsp;<asp:Button ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                                                Text="Löschen" ForeColor="Red" Width="120px" meta:resourcekey="DeleteButtonResource1"
                                                Visible='<%# UserIsAdmin() %>' SkinID="Normal" /><ajaxToolkit:ConfirmButtonExtender
                                                    ID="ConfirmButtonExtender1"
                                                    runat="server" TargetControlID="DeleteButton" ConfirmText="Soll diese Mauslinie wirklich gelöscht werden?"
                                                    Enabled="True">
                                                </ajaxToolkit:ConfirmButtonExtender>
                                        </td>
                                    </tr>
                                </asp:Panel>
                            </table>
                        </ItemTemplate>
                    </asp:FormView>

<asp:SqlDataSource ID="SqlDataSourceEmbryonen" runat="server" ConnectionString="<%$ ConnectionStrings:MouseCryo %>"
                    SelectCommand="SELECT * FROM [Embryonen] WHERE ([Embryo_Id] = @Embryo_Id)" DeleteCommand="DELETE FROM [Embryonen] WHERE [Embryo_Id] = @Embryo_Id"
                    InsertCommand=" a very long SQL INSERT statement"  
                    UpdateCommand=" a similarly long SQL UPDATE" > 
                    <SelectParameters>...</SelectParameters>
                    <DeleteParameters>...</DeleteParameters>
                    <UpdateParameters>...</UpdateParameters>
                    <InsertParameters>...</InsertParameters>
                  </asp:SqlDataSource> 
                </ContentTemplate> 
                <Triggers>...</Triggers> 
             </asp:UpdatePanel> 
          </div> 
    </asp:Content> 

It sounds like your UpdatePanel is not getting refreshed. 听起来您的UpdatePanel没有刷新。

Since you confirmed that the ModeChanging and ModeChanged events occurred, I don't there is actually a problem with your FormView (it seems like a "red herring"). 由于您确认发生了ModeChanging和ModeChanged事件,所以我的FormView实际上没有问题(它看起来像“红鲱鱼”)。

You said you removed a UserControl from the page, and that is when this got broken. 您说您从页面上删除了一个UserControl,也就是当它被破坏时。 It seems likely that this is what has caused the problem. 看来这是造成问题的原因。 Somewhere in the life cycle of your old UserControl, I bet a call was made to UpdatePanel1.Update() , and, though that code may still exist, it is not being called now (because the UC is not there). 我敢打赌,在旧的UserControl的生命周期中的某个地方,调用了UpdatePanel1.Update() ,尽管该代码可能仍然存在,但现在不被调用(因为UC不存在)。

Or, possibly, the UC was explicitly defined as trigger for the UpdatePanel (though, in that case, I would expect you'd get runtime or compile time errors with your ASPX page). 或者,可能是UC被明确定义为UpdatePanel的触发器(尽管在这种情况下,我希望您的ASPX页面会出现运行时或编译时错误)。

In any case, you could probably test this theory by calling the Update() fucntion from the ModeChanged event of your FormView: 无论如何,您可以通过从FormView的ModeChanged事件中调用Update()功能来检验这种理论:

protected void FormView1_ModeChanged(Object sender, EventArgs e)
{
    if(FormView1.CurrentMode == FormViewMode.Edit)
    {
        UpdatePanel1.Update();
    }
}

Mystery solved. 谜团已揭开。

It was, after all, that control about which I said 毕竟,这是我所说的控制权

I tried setting a breakpoint into the Page_Load event of a control which might have stopped working after my other changes, but the breakpoint is never reached 我尝试在控件的Page_Load事件中设置一个断点,该断点在我进行其他更改后可能已停止工作,但从未达到断点

It had its own SqlDataSource, and after a change in the database, the SQL statement stopped working. 它具有自己的SqlDataSource,并且在数据库中进行更改后,SQL语句停止工作。 Sadly, the error must have been thrown before the Page_Load event was reached. 可悲的是,必须在到达Page_Load事件之前引发该错误。 But because the code is set up to swallow error messages without actually handling them (that wasn't me!), I never got a message. 但是因为代码设置为吞下错误消息而没有实际处理它们(那不是我!),所以我从未收到消息。

Luckily, there was also some JavaScript error in the code generated by Microsoft's server side controls, so looking into Chrome developer tools brought me to the right trail and let me unravel what is actually happening. 幸运的是,Microsoft的服务器端控件生成的代码中还存在一些JavaScript错误,因此研究Chrome开发人员工具可以使我走上正确的道路,并让我了解实际发生的情况。

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

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