Reputation: 2524
I am working with an ASP .NET application. It has a "Details.aspx" page where basically, the user can see or edit a data record. The whole page is one giant 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.
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). There are no changes in the code behind file. The EditItemTemplate of the FormView stays the same. The SqlDataSource to which the FormView is bound stays the same. 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. (The Embryonen table still exists). 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.
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" />
<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>
Upvotes: 1
Views: 734
Reputation: 2524
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
It had its own SqlDataSource, and after a change in the database, the SQL statement stopped working. Sadly, the error must have been thrown before the Page_Load event was reached. 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.
Upvotes: 1
Reputation: 11433
It sounds like your UpdatePanel
is not getting refreshed.
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").
You said you removed a UserControl from the page, and that is when this got broken. 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).
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).
In any case, you could probably test this theory by calling the Update()
fucntion from the ModeChanged event of your FormView:
protected void FormView1_ModeChanged(Object sender, EventArgs e)
{
if(FormView1.CurrentMode == FormViewMode.Edit)
{
UpdatePanel1.Update();
}
}
Upvotes: 1