• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 491
  • Last Modified:

FormView mode only changes on 2nd button click

Greetings all,

I have a rather strange problem...

I have a panel that contains buttons and below that another panel that contains a formview.
When the user clicks the button, the method should set the state of the FormView (eg to "Edit").

The problem is that this only happens on a second button click (any button!). When I click the desired button, it goes to the method and executes the code (checked this using breakpoints), but the FormView remains in "ReadOnly" mode. If I click the button a 2nd time (or any other button) it again executes the code within the method, but this time the formview mode is changed and I can edit the data.

Note: I have also tried this without the UpdatePanel - same problem.

Any ideas as to how I get the Edit "state" of the FormView to change


In advance, thanks!!

       allanmark
CODE BEHIND:
 
protected void btnInsertC_Click(object sender, EventArgs e)
    {
          // Note: Changing to Edit mode for test purposes!
           fvSpousal.ChangeMode(FormViewMode.Edit);
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            if (Session["couples"] != null)
            {
                Session["selectedCouple"] = lbxCouples.SelectedIndex;
                couplesList = (List<CoupleName>)Session["couples"];
                lbxCouples.DataSource = couplesList;
                lbxCouples.DataTextField = "Name";
                lbxCouples.DataValueField = "Id";
                lbxCouples.DataBind();
                lbxCouples.SelectedIndex = (int)Session["selectedCouple"];
 
                if (Session["theCouple"] != null)
                {
                    theCouple = (DataTable)Session["theCouple"];
                }
                else
                {
                    GetCoupleDetails(couplesList[lbxCouples.SelectedIndex].Id);
                }
            }
            else
            {
                GetCouples();
            }
        }
        else
        {
            // Not PostBack.
            GetPortfolios();
            GetTitles();
            GetCouples();                        
            Session["selectedCouple"] = lbxCouples.SelectedIndex;           
        }
 
    }
 
 
SOURCE:
 
<%@ Page Language="C#" MasterPageFile="~/MimeMaster01.master" AutoEventWireup="true" CodeFile="People.aspx.cs" Inherits="People" Title="People" %>
<%@ MasterType VirtualPath="~/MimeMaster01.master" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="leftnav" Runat="Server" >  
	................
	........................        
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="rightnav" Runat="Server">
 
    <ajaxext:UpdatePanel ID="uppnlSpousal" runat="server">
    <ContentTemplate>    
        
    <asp:Panel ID="pnlSpousalTitle" runat="server" CssClass="collapsePanelHeader"> 
        <asp:Image ID="imgCollapse" runat="server" ImageUrl="~/Graphics/expand.jpg"/>&nbsp;&nbsp;
            Spousal Details&nbsp;&nbsp;        
        <asp:Label ID="Label1" runat="server">(Show Details...)</asp:Label>
        <br />
        <asp:Button ID="btnInsertC" runat="Server" Text="Insert" CssClass="buttonsOnCollapseHeader" OnClick="btnInsertC_Click" Enabled="true"  />
        &nbsp;&nbsp;
        ................
    </asp:Panel>
    <br />
    
    <asp:Panel ID="pnlSpousalContent" runat="server" CssClass="collapsePanel">        
 
       <ajaxToolkit:CollapsiblePanelExtender ID="cpe" runat="Server" 
            TargetControlID="pnlSpousalContent"
            ExpandControlID="imgCollapse" 
            CollapseControlID="imgCollapse" 
            Collapsed="false"
            TextLabelID="Label1" 
            ExpandedText="(Hide ...)" 
            CollapsedText="(Show ...)"
            ImageControlID="Image1" 
            ExpandedImage="Graphics/collapse.jpg"
            CollapsedImage="~/Graphics/expand.jpg"
            SuppressPostBack="true" AutoExpand="true" >
        </ajaxToolkit:CollapsiblePanelExtender>
        
        <br />
        <asp:FormView ID="fvSpousal" runat="server" DefaultMode="ReadOnly" OnDataBound="fvSpousal_DataBound" 
             OnItemCommand="FvSpousal_ItemCommand" CssClass="smallFontSize" >  
                         
            <ItemTemplate>
            
                <asp:Label ID="lblCoupleSurname_CI" runat="Server" Text="Surname:"></asp:Label>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:TextBox ID="txtCoupleSurname_CI" runat="server" Text=<%# Eval("C_Surname")%> Enabled="false" />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="lblMaritalStat_CI" runat="server" Text="Marital Status: "></asp:Label>
                <asp:DropDownList  ID="ddlMarStatus_CI" runat="server" SelectedValue=<%# Eval("C_Mar_Status") %>
                Enabled="false" >
                   <asp:ListItem Value="M">Married</asp:ListItem>
                   <asp:ListItem Value="D">Divorced</asp:ListItem>
                   <asp:ListItem Value="S">Separated</asp:ListItem>
                   <asp:ListItem Value="W">Widowed</asp:ListItem>
                </asp:DropDownList>     
                ..............................
		..........................
                <br />        
            </ItemTemplate>                                              
            <EditItemTemplate>
                <asp:Label ID="lblCoupleSurname_CE" runat="Server" Text="Surname:"></asp:Label>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:TextBox ID="txtCoupleSurname_CE" runat="server" Text=<%# Eval("C_Surname")%> />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="lblMaritalStat_CE" runat="server" Text="Marital Status: "></asp:Label>
                <asp:DropDownList  ID="ddlMarStatus_CE" runat="server" SelectedValue=<%# Eval("C_Mar_Status") %>  >
                   <asp:ListItem Value="M">Married</asp:ListItem>
                   <asp:ListItem Value="D">Divorced</asp:ListItem>
                   <asp:ListItem Value="S">Separated</asp:ListItem>
                   <asp:ListItem Value="W">Widowed</asp:ListItem>
                </asp:DropDownList>     
                ....................................
		................................
                </asp:Panel>
                <!-- <asp:Panel ID="pnlSpouse2_CE" > --> 
                <br />        
            </EditItemTemplate>
                              
        </asp:FormView>   
                                     
    </asp:Panel>
    <!-- <asp:Panel ID="pnlSpousalContent" >  -->
    
    </ContentTemplate>
    </ajaxext:UpdatePanel>              
    <br />
    
    <asp:Panel ID="pnl01" runat="server" BackColor="Lime" Height="75px" Width="98%"></asp:Panel>
    
</asp:Content>

Open in new window

0
allanmark
Asked:
allanmark
1 Solution
 
GiftsonDJohnCommented:
Hi

You have to do a databind again on the button click.
0
 
allanmarkAuthor Commented:
Excellent!!  many thanks!!!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now