First ModalPopupExtender example and some problems I run into

Just start to learn Ajax, and I start to use ModalPopupExtender for the first time.


Here are the essential code behind, it will show you how to update and insert record by using gridview and formview with ModalPopupExtender:

-----------------------------------------------------------------------------------------------------------------------------------

<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="upOffice" runat="server">
            <ContentTemplate>
            <asp:Panel ID="pnSearch" runat="server">

            ....................

            <--In gridview we have a edit button to call edit mode --/>
                    <asp:GridView ID="gvOffice" runat="server">
                        <Columns>

                            .............
                            <asp:TemplateField HeaderText="Action" ShowHeader="False">
                                <ItemTemplate>
                                    <asp:ImageButton ID="IBTEditOffice" runat="server" CommandArgument='<%# Eval("ID") %>' CommandName="IBTEdit_Click" CausesValidation="false" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

        <%

 

        protected void gvOffice_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToString() == "IBTEdit_Click" )
            {
                Session["sesOfficeID"] = e.CommandArgument.ToString();
                fvOffice.ChangeMode(FormViewMode.Edit);
                fvOffice.DataBind();
                mpeModalPopup .Show();
            }

        }

        %>

 

            <asp:Button ID="btnCreateOffice" runat="server"
                                Text="Create New Office" CssClass="button" CausesValidation="false"
                                οnclick="btnCreateOffice_Click " />

            <%

                    protected void btnCreateOffice_Click (object sender, EventArgs e)
                    {
                        fvOffice.ChangeMode(FormViewMode.Insert);
                        fvOffice.DataBind();
                        mpeModalPopup .Show();
                    }

            %>

            ....................

            </asp:Panel>
            <asp:Panel ID="pnModalPopup " runat="server" CssClass="modalPopup" Style="display: none" Width="540px">

                    <asp:FormView ID="fvOffice" runat="server">

                       <EditItemTemplate>  

                       .................
                       <asp:Button ID="btnUpdate" runat="server" CommandName="Update" Text="Update" />

                       ...................

                       </EditItemTemplate>      

                       <InsertItemTemplate>

                       ...................

   
                       <asp:Button ID="btnInsert" runat="server" CommandName="Insert" Text="Insert" />

                       ...................

                   </InsertItemTemplate>

                   </asp:FormView>

            </asp:Panel>
            <asp:HiddenField ID="hdnField " runat="server" />
            <asp:ModalPopupExtender ID="mpeModalPopup" runat="server"
                        TargetControlID="hdnField"
                        PopupControlID="pnModalPopup"
                        BackgroundCssClass="modalBackground"/>

        </ContentTemplate>
    </asp:UpdatePanel>

 

----------------------------------------------------------------------------------------------------------------------------------

 

And ModalPopupExtender will prevent button triger Click function if you set the button as TargetControlID , that's why we have to use a hiddenfield.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值