Formview and MS-Ajax UpdatePanel

I have a problem with the conditional display of the form edit button after the partial postback caused by the form control. I have an edit button defined in ItemTemplate, like this:

<asp:FormView ID="fvGenericDetails" runat="server">
    <ItemTemplate>
       <asp:Button ID="btnEditGenericDetails" runat="server" Visible="false" CausesValidation="False" CssClass="prepend-top" CommandName="Edit" Text="Edit Generic Details" />
</ItemTemplate>

The button is conditionally displayed based on user privileges in the page load event:

If CurrentUser.HasAdminStatus and fvGenericDetails.CurrentMode = FormViewMode.ReadOnly Then
    Dim btnEditGenericDetails As Button =  CType(Me.fvGenericDetails.FindControl("btnEditGenericDetails"), Button)
    btnEditGenericDetails.Visible = True
End If

The problem is that since the formview control is in the UpdatePanel, the partial postback does not raise the page load event when the control returns to read-only mode and the edit button does not become visible. What event should I use to enable this partial postback?

Edit: after debugging the page after partial postback, the page really falls into the page_load event, but formview.currentmode = edit: |

I tried to use the ModeChanged event without success. The answer is only not to use a form control?

Thanks:)

0
source share
3 answers

I think the best place for this would be in the FormView_ModeChanging event:

Protected Sub FormView1_ItemDataBound(ByVal sender As Object, ByVal e As EventArgs) Handles FormView1.ItemDataBound
        If e.NewMode = FormViewMode.ReadOnly Then
            If CurrentUser.HasAdminStatus Then
                Dim btnEditGenericDetails As Button = CType(Me.fvGenericDetails.FindControl("btnEditGenericDetails"), Button)
                btnEditGenericDetails.Visible = True

            End If
        End If
End Sub

Alright ... If you put your code in an ItemDataBound event handler , then it should work. This is because InsertTemplate does not exist until the object is attached to the FormView.

0
source

,

if(!IsPostBack){} //don't know what the VB equivalent is

. IF , fvGenericDetails.CurrentMode

0

man, this may help, but try changing the appearance of the form view on the Prerender or Init evnt page

0
source

All Articles