locked
ModalPopupExtender - Controls still cache previous selections. RRS feed

  • Question

  • User1974059868 posted

    Hi guys.

    I'm having an issue with the controls on ModalPopupExtender.

    I have a Gridview and when users click on the header of one of the column, it will show ModalPopupExtender with dropdownlists and checkboxlist and users can click the Save button. The issue that I'm having is, when users click on the Save button, save process on backend will be executed and ModalPopupExtender will be closed. After that users can click on the header again to save more data. But when users click on the headers on second time onwards, the controls will cache previous selection even I can see that it wasn't selected on ModalPopupExtender.

    For example, if I selected index 0 on the dropdownlist and click save and ModalPopupExtender closed. I clicked on the header again to add more data, I selected index 1 on the dropdownlist and click Save, and dropdownlist selectedindex is still 0. Same went with the checkboxlist.

    Please help me.

    Code on aspx page.

      <script type="text/javascript">
          function close() {
              $find('ModalPopupUploadFile1').hide();
          }
          
          function initiateProduct() {
             
              var ddlProductType = document.getElementById("<%=ddlProductType.ClientID%>");
              ddlProductType.selectedIndex = 0;
    </script>
    
    <asp:UpdatePanel ID="UpdatePanel29" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <table width="100%">
                        <tr>
                            <td width="10%"></td>
                            <td width="90%"></td>
                        </tr>
                        
                        <tr>
                            <td colspan="2">
                            <asp:Button id="asp_btnRefresh" Style="display: none"  onclick="Refresh_Click" runat="server"></asp:Button>
                            <asp:GridView ID="gvProduct" runat="server" AllowSorting="True"
                                AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
                                BorderWidth="1px" CellPadding="4" DataKeyNames="NO"
                                EmptyDataText="There are no data records to display."
                                ForeColor="Black" CssClass="tablestyle" Font-Names="Arial" 
                                Font-Size="8pt" Width="100%" onrowcommand="gvProduct_RowCommand"
                                PageSize="5" ShowFooter="True" EnableModelValidation="True" >
                                <RowStyle BackColor="White" CssClass="rowstyle" />
                                <Columns>
                                    <asp:BoundField DataField="PRODUCT_TYPE" HeaderText="Product Type" />                                
                                    <asp:BoundField DataField="PRODUCT" HeaderText="Step" />
                                    <asp:TemplateField ShowHeader="False">
                                        <HeaderTemplate>
                                            <asp:ImageButton ID="linkAdd" runat="server" AlternateText="Add" ToolTip="Add" ImageUrl="~/img/tDocumentAdd.png"  
                                                OnClick="SetNewFileID" OnClientClick="initiateProduct()" />
                                            <asp:Button ID="btnHidden" runat="server" Style="display:none"/>
                                            <asp:ModalPopupExtender ID="ModalPopupUploadFile1" runat="server" 
                                                BackgroundCssClass="modalBackground" CancelControlID="btnHiddenCancel" 
                                                DropShadow="true" PopupControlID="PUpload" 
                                                PopupDragHandleControlID="PUploadSub" TargetControlID="btnHidden" />
                                            <%--<ajaxtoolkit:ModalPopupExtender ID="ModalPopupUploadFile1" runat="server" 
                                                BackgroundCssClass="modalBackground" CancelControlID="btnHiddenCancel" 
                                                DropShadow="true" PopupControlID="PUpload" 
                                                PopupDragHandleControlID="PUploadSub" TargetControlID="btnHidden" />--%>
                                        </HeaderTemplate>
                                        <ItemTemplate>  
                                            <center>
                                                <asp:ImageButton ID="ImgEdit" runat="server" AlternateText="Edit" ToolTip="Edit" 
                                                     CommandArgument='<%# Eval("id") %>' CommandName="EditProduct" Height="15" 
                                                     ImageUrl="~/_assets/img/EditButton.png" Width="15" />
                                                <asp:ImageButton ID="btnDelete" runat="server" ToolTip="Delete" 
                                                        ImageUrl="~/_assets/img/button_cancel.png" Width="15" Height="15" 
                                                        CommandName="DeleteProduct" CommandArgument='<%# Eval("id") %>' />
                                            </center>
                                        </ItemTemplate>
                                        <HeaderStyle Width="50px" />
                                        <ItemStyle Width="80px" HorizontalAlign="Center" VerticalAlign="Middle" />
                                    </asp:TemplateField>
                                </Columns>
                                <FooterStyle BackColor="#E4E4E4" CssClass="footerstyle" />                            
                                <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
                                <HeaderStyle CssClass="headerstyle" ForeColor="#333333" BackColor="#E4E4E4" />
                                <AlternatingRowStyle BackColor="#FAFAF9" CssClass="altrowstyle" />
                            </asp:GridView>
                            </td>
                        </tr>
                    </table>
                </asp:Panel>
              <asp:Panel ID="PUpload" runat="server" Style="display: none" CssClass="modalPopupImplementationD5">
                <div style="float:right">
                      <asp:ImageButton ID="CancelButton" runat="server" CssClass="button_cancel" ImageUrl="~/_assets/img/button_cancel.png" ToolTip="Cancel" OnClick="CancelButton_OnClick" />
                      <asp:Button ID="btnHiddenCancel" runat="server" Style="display:none"/>  
                </div>
                <asp:Panel ID="PUploadSub" runat="server" CssClass="modalDragHandle">
                    <div>
                         <asp:Label ID="lblTitle" runat="server" Text="Product Related Details" Width="300px" Font-Bold="True" Font-Size="12pt"></asp:Label>               
                    </div>
                </asp:Panel>
                <div>                  
                    <table>
                        <tr>
                            <td width="150"></td>
                            <td width="200"></td>
                        </tr>                    
                        <tr>
                            <td>Product Type:</td>
                            <td><asp:DropDownList runat="server" ID="ddlProductType" Width="200" ></asp:DropDownList></td>
                        </tr>
                        <tr>
                            <td style="vertical-align:top">Step:</td>
                            <td>
                                <div style="OVERFLOW-Y:scroll; WIDTH:300px; HEIGHT:100px">
                                    <asp:CheckBoxList runat="server" ID="cblProduct" Width="200" ForeColor="Black" ></asp:CheckBoxList>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2"><asp:Label runat="server" ID="lblError" ForeColor="Red"></asp:Label></td>
                        </tr>
                        <tr>
                            <td colspan="2">&nbsp;</td>
                        </tr>
                        <tr>
                            <td></td>
                            <td><asp:Button runat="server" ID="btnSave" Text="Submit" onclick="btnSubmit_Click" /></td>
                        </tr>
                </table>
            </div>
        </asp:Panel>
     </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="gvProduct" />
                <asp:AsyncPostBackTrigger ControlID="CancelButton" />
                <asp:AsyncPostBackTrigger ControlID="btnHiddenCancel" />
                <asp:AsyncPostBackTrigger ControlID="asp_btnRefresh" />            
            </Triggers>
        </asp:UpdatePanel>

    Backend code.

    protected void SetNewFileID(object sender, ImageClickEventArgs e)
        {
    
            BindControls();
    
            GridViewRow row = ((GridViewRow)((ImageButton)sender).NamingContainer);
            //NamingContainer return the container that the control sits in
            AjaxControlToolkit.ModalPopupExtender mpe =
                               (AjaxControlToolkit.ModalPopupExtender)row.FindControl("ModalPopupUploadFile1");
            mpe.Show(); //show the modal popup extender
        }
    
    private void BindControls()
        {
           
            ddlProductType.Items.Clear();
            ds = GetFromConfig("PRODUCT_TYPE", true, conn);        
            ClsDataBinding.BindDataTableList(ddlProductType, ds.Tables[0], "", "");
    
          
            ds = GetFromConfig("PRODUCT", true, conn);
            DataTable dt = ds.Tables[0];
    
            cblProduct.Items.Clear();
    
            foreach (DataRow item in dt.Rows)
            {
                cblProduct.Items.Add(item["value"].ToString());
            }
    
            cblProduct.DataBind();
    
            foreach (ListItem listItem in cblProduct.Items)
            {
                if (listItem.Selected==true)
                    listItem.Selected = false;
            }
        }
    
    protected void btnSubmit_Click(object sender, EventArgs e)
        {
    
            if (cblProduct.SelectedIndex == -1)
            {
                lblError.Text = "Please select Product.";
            }
    
            else
            {
                string Product = "";
    
                foreach (ListItem item in cblProduct.Items)
                {
                    if (item.Selected)
                    {
                        Product = Product + item.Text + "; ";
                    }
                }
    
                SetProduct(ddlProductType.SelectedItem.Text, Product);
    
                ddlProductType.SelectedIndex = 0;           
    
                foreach (ListItem item in cblProduct.Items)
                {
                    if (item.Selected)
                    {
                        item.Selected = false;
                    }
                }
    
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
    
                BindData();
                UpdatePanel29.Update();
    
                ModalPopupExtender modal = (ModalPopupExtender)gvGridView.HeaderRow.FindControl("ModalPopupUploadFile1");
                modal.Hide();           
              
            }
        }
    
    protected void Refresh_Click(object sender, EventArgs args)
        {
            //  update the grids contents
            // this.gvAttach.DataBind();
    
            ddlProductType.SelectedIndex = 0;
            
    
            foreach (ListItem item in cblProduct.Items)
            {
                if (item.Selected)
                {
                    item.Selected = false;
                }
            }
    
            BindData();
        }



    Monday, November 4, 2013 10:17 PM

Answers

  • User1243880387 posted

      <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />

    Remove this and problem will be solved.

    :)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 6, 2013 6:55 AM