views:

714

answers:

3

I have an issue with the conditional display of the formview edit button after a partial postback triggered by the formview control. I have an edit button defined in the 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 privilages 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 I'm having is that as the formview control is in an UpdatePanel, the partial postback does not trigger the page load event when the control goes back to read-only mode, and the edit button is not made visible. What event should I be using to allow for this partial postback?

Edit: Having debugged the page, after the partial postback, the page does indeed hit the page_load event but the formview.currentmode = edit :|

I've tried using the ModeChanged event without success. Is the answer just not to use the formview control?

Thanks :)

A: 

I think the best place for that would be at the FormView_ModeChanging event like this:

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

Ok... If you put your code in the ItemDataBound event handler then it should work. It has something to do with the fact that InsertTemplate doesn't exist until there is an object bound to the FormView.

J.13.L
That would certainly seem like the right approach but unfortunately the runtime returns Object reference not set to an instance of an object, referencing the button.
Bayard Randel
A: 

unless you have your button display logic wrapped in

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

your code should work just fine. start the debugger and put a breakpoint on your IF statement, and see what fvGenericDetails.CurrentMode evaluates to

roman m
A: 

man, may be this will helps,but try to change the formview view on Prerender or Init page evnt