Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
It sounds complex, but what I want really is SO simple, I'm surprised that I'm hitting complications upon every turn.

What I need: Almost every page I'm building will have the same UI and layout. The page must have a button to launch a modal popup, containing a form to add new records. The page also has a GridView which displays the current records. All of this is contained in an UpdatePanel (which is where the complexity becomes overwhelming.)

I have everything I need in the ModalPopupExtender...I have it working exactly as I need.

The problem I'm having is the GridView. There is a delete button next to each record, which fires a click event. There is also a checkbox next to each record which allows me to set a flag (fired on click as well.) The delete and checkbox click events work exactly as expected when NOT wrapped in an UpdatePanel. When I do wrap them in an UpdatePanel, nothing happens at all - the events aren't fired. I'm sure it's a Page Lifecycle thing but I can't spot where I went wrong.

I also need the ModalPopupExtender to refresh the GridView when either button is clicked. So, to summarize:

1. User clicks button at top, gets modal popup, submits data or cancels
2. Underlying GridView is refreshed
3. User clicks delete icon or checkbox next to a record
4. GridView is refreshed and displays change in data

#1 works...the rest does not. When I click the delete icon or the checkbox, the events are not fired. The GridView is re-bound but the RowCreated event then does not fire.

The Web Form page:

ASP.NET
<asp:updatepanel id="ConfigSMTPUpdatepanel" runat="server">
    <contenttemplate>
        <table style="width:100%;">
            <tr>
                <td colspan="2">
                    <!-- modal popup button and div -->
                    <asp:imagebutton id="AddNewButton" runat="server" alternatetext="Add New SMTP Server" imageurl="~/Images/plus.gif" tooltip="Add New SMTP Server" />
                    <asp:modalpopupextender
                        id="AddNewModalPopupExtender"
                        targetcontrolid="AddNewButton"
                        popupcontrolid="AddNewPanel"
                        popupdraghandlecontrolid="popupTitlebar"
                        backgroundcssclass="modalPopupBg"
                      dropshadow="true"
                        drag="true"
                        runat="server">
                    </asp:modalpopupextender>
                    <div id="AddNewPanel"  runat="server" style="display: none;" class="popupConfirmation">
                        <div class="popupContainer">
                            <div id="popupTitlebar" class="popupTitlebar">
                                <div class="titlebarLeft">Popup Header</div>
                                <div class="titlebarRight"></div>
                            </div>
                            <div class="popupBody">
                                <p>
                                    <table style="width:100%;">
                                        <tr>
                                            <td colspan="2">
                                                <asp:validationsummary ID="ConfigSMTPValidationSummary" runat="server" cssclass="validation" validationgroup="ConfigSMTPGroup" ShowModelStateErrors="true" />
                                            </td>
                                        </tr>
                                        <!-- SEARCH FORM -->
                                        <tr>
                                            <td class="fieldLabel">SMTP Address<span class="required">*</span></td>
                                            <td>
                                                <asp:textbox id="SMTPServer" cssclass="input" clientidmode="Static" runat="server" width="400px"></asp:textbox>
                                                <asp:requiredfieldvalidator id="SMTPServerValidator" runat="server" controltovalidate="SMTPServer" validationgroup="ConfigSMTPGroup" errormessage="SMTP Server Required!"></asp:requiredfieldvalidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="fieldLabel">Description</td>
                                            <td>
                                                <asp:textbox id="Description" cssclass="input" clientidmode="Static" runat="server" textmode="MultiLine" columns="55" rows="5">
                                                </asp:textbox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td> </td>
                                            <td>
                                                <asp:checkbox id="IsDefault" cssclass="input" text="Set As Default" runat="server" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2"> </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" class="submit">
                                                <asp:button ID="SaveButton" Text="Save Record" runat="server" validationgroup="ConfigSMTPGroup" onclick="SaveButton_Click"></asp:button>
                                                 
                                                <asp:button ID="CancelButton" Text="Cancel" runat="server" CausesValidation="False" onclick="CancelButton_Click"></asp:button>
                                            </td>
                                        </tr>
                                    </table>
                                </p>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <!-- SEARCH RESULTS -->
                    <asp:gridview
                        id="ConfigSMTPGrid"
                        runat="server"
                        autogeneratecolumns="False"
                        datakeynames="ID"
                        onrowcreated="ConfigSMTPGrid_RowCreated">
                        <alternatingrowstyle backcolor="#F3F3F3" />
                        <columns>
                            <asp:templatefield>
                                <itemtemplate>
                                    <asp:imagebutton
                                        id="DeleteButton"
                                        runat="server"
                                        causesvalidation="False"
                                        commandname="Delete"
                                        commandargument='<%# Eval("ID") %>'
                                        imageurl="~/Images/del_icon.gif"
                                        alternatetext="Delete"
                                        onclientclick="return getDeleteMessageExt();"
                                        oncommand="DeleteButton_Command" />
                                </itemtemplate>
                            </asp:templatefield>
                            <asp:boundfield datafield="SMTPServer" headertext="Address" />
                            <asp:boundfield datafield="Description" headertext="Description" />
                            <asp:boundfield datafield="CreateDate" headertext="Created" />
                            <asp:templatefield headertext="Default">
                                <itemtemplate>
                                    <asp:checkbox id="IsDefaultGridCheck" runat="server" autopostback="true" />
                                </itemtemplate>
                            </asp:templatefield>
                        </columns>
                    </asp:gridview>
                </td>
            </tr>
        </table>
    </contenttemplate>
    <triggers>
        <asp:asyncpostbacktrigger controlid="ConfigSMTPGrid" />
    </triggers>
</asp:updatepanel>


...code-behind:

C#
using ...etc...etc...etc...

public partial class ControlCenter_ConfigSMTP : System.Web.UI.Page
{
    protected void Page_PreRender(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            this.BindData();
    }

    protected void BindData()
    {
            this.ConfigSMTPGrid.DataSource = <bound List>;
            this.ConfigSMTPGrid.DataBind();
    }

    protected void SaveButton_Click(object sender, EventArgs e)
    {
            //save entity

            //update grid?  Didn't work...
            //this.ConfigSMTPUpdatepanel.Update();
    }

    protected void CancelButton_Click(object sender, EventArgs e)
    {
        //this.ConfigSMTPUpdatepanel.Update();
    }
}
Posted
Updated 5-Dec-13 10:34am
v2
Comments
Thanks7872 4-Dec-13 23:11pm    
Remove unnecessary code blocks. Server side code has nothing to do with this issue.
zambizzi 5-Dec-13 16:30pm    
Apologies...thought I had posted a leaner version from another board. My mistake. Better?
Thanks7872 5-Dec-13 23:06pm    
No. I said remove server side code. I clearly stated that problem has nothing to do with server side code.Always remember on any forum,if you want to be taken seriously,you should always post the smallest possible snippet of code. As you can see,there are no answers posted since 23hrs. The reason is no one would like to go through such lengthy code block.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900