ModalPopup/UpdatePanel: nothing happen on DetailsView Update/Cancel

Last post 09-04-2008 10:33 PM by Zhi-Qiang Ni - MSFT. 2 replies.

Sort Posts:

  • ModalPopup/UpdatePanel: nothing happen on DetailsView Update/Cancel

    08-31-2008, 11:23 PM
    • Member
      20 point Member
    • legal101205
    • Member since 02-06-2008, 3:05 PM
    • Posts 27

    Hi and thanks in advance.

    I use the UpdatePanel, and not the Panel to set the GridView.SelectedIndex without page reloading.

    1. Check one CheckBox in the GridView
    2. Autopostback to true allow CheckBox1_CheckedChanged to set the GridView1.SelectedIndex
    3. DetailsView in the UpdatePanel is updated because its objectdatasource parameter is fixed to GridView1.SelectedIndex
    4. Clicking on the button launch the modal popup and display the DetailsView corresponding to the item checked

    If i use a simple Panel, the DetailsView keep a -1 index.

    My problem is that when i click on Update / Insert or Delete, nothing happen: i am blocked in the modal popup and the data is not modified as you can see.

    Here is the code:

      

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
        CodeFile="Copy of Copy of Default6.aspx.cs" Inherits="Tournaments2_Default6" %>
    
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel2" runat="server">
            <ContentTemplate>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="TournoiID"
                    DataSourceID="ObjectDataSource1">
                    <Columns>
                        <asp:TemplateField ShowHeader="False">
                            <ItemTemplate>
                                <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged"
                                    AutoPostBack="True" />
                                <cc1:MutuallyExclusiveCheckBoxExtender ID="MutuallyExclusiveCheckBoxExtender1" runat="server"
                                    Key="CheckBoxes" TargetControlID="CheckBox1">
                                </cc1:MutuallyExclusiveCheckBoxExtender>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="TournoiID" HeaderText="TournoiID" InsertVisible="False"
                            ReadOnly="True" SortExpression="TournoiID" />
                        <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
                        <asp:BoundField DataField="Nom" HeaderText="Nom" SortExpression="Nom" />
                        <asp:BoundField DataField="Texte" HeaderText="Texte" SortExpression="Texte" />
                        <asp:BoundField DataField="VarianteID" HeaderText="VarianteID" SortExpression="VarianteID" />
                        <asp:CheckBoxField DataField="OptionELO" HeaderText="OptionELO" SortExpression="OptionELO" />
                        <asp:BoundField DataField="TempsCoup" HeaderText="TempsCoup" SortExpression="TempsCoup" />
                        <asp:BoundField DataField="TempsPartie" HeaderText="TempsPartie" SortExpression="TempsPartie" />
                        <asp:BoundField DataField="MaxJoueurs" HeaderText="MaxJoueurs" SortExpression="MaxJoueurs" />
                        <asp:BoundField DataField="NomDeVariante" HeaderText="NomDeVariante" SortExpression="NomDeVariante" />
                    </Columns>
                </asp:GridView>
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
            SelectMethod="GetTournois" TypeName="TournoisBLL" DeleteMethod="DeleteTournoi"
            InsertMethod="AddTournoi" UpdateMethod="UpdateTournoi">
            <DeleteParameters>
                <asp:Parameter Name="tournoiID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="date" Type="DateTime" />
                <asp:Parameter Name="nom" Type="String" />
                <asp:Parameter Name="texte" Type="String" />
                <asp:Parameter Name="varianteID" Type="Int32" />
                <asp:Parameter Name="optionElo" Type="Boolean" />
                <asp:Parameter Name="tempsCoup" Type="Int32" />
                <asp:Parameter Name="tempsPartie" Type="Int32" />
                <asp:Parameter Name="maxJoueurs" Type="Int32" />
                <asp:Parameter Name="tournoiID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="date" Type="DateTime" />
                <asp:Parameter Name="nom" Type="String" />
                <asp:Parameter Name="texte" Type="String" />
                <asp:Parameter Name="varianteID" Type="Int32" />
                <asp:Parameter Name="optionElo" Type="Boolean" />
                <asp:Parameter Name="tempsCoup" Type="Int32" />
                <asp:Parameter Name="tempsPartie" Type="Int32" />
                <asp:Parameter Name="maxJoueur" Type="Int32" />
            </InsertParameters>
        </asp:ObjectDataSource>
        <br />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AutoGenerateRows="False"
                    DataKeyNames="TournoiID" DataSourceID="ObjectDataSource2" 
                    DefaultMode="Edit" onpageindexchanging="DetailsView1_PageIndexChanging">
                    <Fields>
                        <asp:BoundField DataField="TournoiID" HeaderText="TournoiID" InsertVisible="False"
                            ReadOnly="True" SortExpression="TournoiID" />
                        <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
                        <asp:BoundField DataField="Nom" HeaderText="Nom" SortExpression="Nom" />
                        <asp:BoundField DataField="Texte" HeaderText="Texte" SortExpression="Texte" />
                        <asp:BoundField DataField="VarianteID" HeaderText="VarianteID" SortExpression="VarianteID" />
                        <asp:CheckBoxField DataField="OptionELO" HeaderText="OptionELO" SortExpression="OptionELO" />
                        <asp:BoundField DataField="TempsCoup" HeaderText="TempsCoup" SortExpression="TempsCoup" />
                        <asp:BoundField DataField="TempsPartie" HeaderText="TempsPartie" SortExpression="TempsPartie" />
                        <asp:BoundField DataField="MaxJoueurs" HeaderText="MaxJoueurs" SortExpression="MaxJoueurs" />
                        <asp:BoundField DataField="NomDeVariante" HeaderText="NomDeVariante" SortExpression="NomDeVariante" />
                        <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
                    </Fields>
                </asp:DetailsView>
            </ContentTemplate>
        </asp:UpdatePanel>
        <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" OldValuesParameterFormatString="original_{0}"
            SelectMethod="GetTournoiByTournoiID" TypeName="TournoisBLL" UpdateMethod="UpdateTournoi"
            DeleteMethod="DeleteTournoi" InsertMethod="AddTournoi">
            <DeleteParameters>
                <asp:Parameter Name="tournoiID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="date" Type="DateTime" />
                <asp:Parameter Name="nom" Type="String" />
                <asp:Parameter Name="texte" Type="String" />
                <asp:Parameter Name="varianteID" Type="Int32" />
                <asp:Parameter Name="optionElo" Type="Boolean" />
                <asp:Parameter Name="tempsCoup" Type="Int32" />
                <asp:Parameter Name="tempsPartie" Type="Int32" />
                <asp:Parameter Name="maxJoueurs" Type="Int32" />
                <asp:Parameter Name="tournoiID" Type="Int32" />
            </UpdateParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" Name="TournoiID" PropertyName="SelectedIndex"
                    Type="Int32" />
            </SelectParameters>
            <InsertParameters>
                <asp:Parameter Name="date" Type="DateTime" />
                <asp:Parameter Name="nom" Type="String" />
                <asp:Parameter Name="texte" Type="String" />
                <asp:Parameter Name="varianteID" Type="Int32" />
                <asp:Parameter Name="optionElo" Type="Boolean" />
                <asp:Parameter Name="tempsCoup" Type="Int32" />
                <asp:Parameter Name="tempsPartie" Type="Int32" />
                <asp:Parameter Name="maxJoueur" Type="Int32" />
            </InsertParameters>
        </asp:ObjectDataSource>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <br />
        <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Button1"
            PopupControlID="UpdatePanel1" BackgroundCssClass="modalBackground" >
        </cc1:ModalPopupExtender>
    </asp:Content>
     

    And the code behind:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Tournaments2_Default6 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            foreach (GridViewRow rowItem in GridView1.Rows)
            {
                CheckBox chk;
                chk = (CheckBox)(rowItem.Cells[0].FindControl("CheckBox1"));
    
                if (chk.Checked)
                {
                    GridView1.SelectedIndex = (int)GridView1.DataKeys[rowItem.RowIndex]["TournoiID"];
                }
            }
        }
    }
    

     

     

    Please, mark as "Answered" if this solves the problem.
  • Re: ModalPopup/UpdatePanel: nothing happen on DetailsView Update/Cancel

    09-01-2008, 6:24 PM
    • Member
      20 point Member
    • legal101205
    • Member since 02-06-2008, 3:05 PM
    • Posts 27

    No suggestion. Please let me know if the post is not clear.

    Please, mark as "Answered" if this solves the problem.
  • Re: ModalPopup/UpdatePanel: nothing happen on DetailsView Update/Cancel

    09-04-2008, 10:33 PM
    Answer

    Hi,

    Place all the controls inside one UpdatePanel(do not use UpdatePanel separately) and have a test.

    What my thought of the cause is the UpdatePanel2 did not has a trigger which handle the changing of the Controls in the UpdatePanel1, then the GridView would not reload its data from the DataBase.

    Please let me know whether I have misunderstood you.

    Best regards,

    Zhi-Qiang Ni

    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question.
Page 1 of 1 (3 items)