0

我有一个按钮,可以在数据库中保存记录,但希望用户按下按钮以通知注册成功,在另一种情况下通知此类注册存在。可以通过模态弹出扩展 (AJAX)
完成此功能在 asp.net C# 中完成

这是服务器端的代码

protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (!DALAtribut.CheckId("SELECT * FROM AtributPhone WHERE ID_Employee = '" + DDLEmployeeCreate.SelectedItem.Value.ToString() + "'"))
            {
                AtributPhone atribut = new AtributPhone()
                {
                    ID = Guid.NewGuid(),
                    ID_Category = Guid.Parse(DDLSubCategoryCreate.SelectedItem.Value),
                    ID_Employee = Guid.Parse(DDLEmployeeCreate.SelectedItem.Value),
                    ID_Institution = Guid.Parse(DDLInstitutionCreate.SelectedItem.Value),
                    ID_Office = Guid.Parse(DDLOfficeCreate.SelectedItem.Value),
                    ID_Phone = Guid.Parse(DDLPhoneCreate.SelectedItem.Value)
                };

                bd.AtributPhones.AddObject(atribut);
                bd.SaveChanges();
                isValid = false;
                //btnAdd.OnClientClick = "return confirm('Registration was successfully added!');";
            }
            gvAtribut.DataBind();
        }

和这里

<%@ Page Title="Atribute" Language="C#" MasterPageFile="~/Administrator/SiteAdmin.Master"
    AutoEventWireup="true" CodeBehind="AtributsPhone.aspx.cs" Inherits="ContactData.Administrator.AtributsPhone" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        function ShowMyModalPopupSuccess() {
            var modal = $find('mpeSuccess');
            modal.show();
        }
        function HideModalPopupSuccess() {
            var modal = $find('mpeSuccess');
            modal.hide();
        }
        function fnClickSuccess(sender, e) {
            __doPostBack(sender, e);
        }
    </script>
    <asp:ScriptManager ID="smAtribut" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="upAtribut" runat="server">
        <ContentTemplate>
            <table>
                <tr>
                    <td class="tableCSS" style="width: 180px;" align="right">
                        Institution :
                    </td>
                    <td class="tableCSS">
                        <asp:DropDownList ID="DDLInstitutionCreate" runat="server" AutoPostBack="True" Width="250px"
                            OnSelectedIndexChanged="DDLInstitutionCreate_SelectedIndexChanged" />
                    </td>
                </tr>
                <tr>
                    <td class="tableCSS" style="width: 180px;" align="right">
                        Phone :
                    </td>
                    <td class="tableCSS">
                        <asp:DropDownList ID="DDLPhoneCreate" runat="server" Width="250px" OnSelectedIndexChanged="DDLPhoneCreate_SelectedIndexChanged"
                            AutoPostBack="True" />
                    </td>
                </tr>
                <tr>
                    <td class="tableCSS" style="width: 180px;" align="right">
                        Section :
                    </td>
                    <td class="tableCSS">
                        <asp:DropDownList ID="DDLSubCategoryCreate" runat="server" Width="250px" OnSelectedIndexChanged="DDLSubCategoryCreate_SelectedIndexChanged"
                            AutoPostBack="True" />
                    </td>
                </tr>
                <tr>
                    <td class="tableCSS" style="width: 180px;" align="right">
                        Employee :
                    </td>
                    <td class="tableCSS">
                        <asp:DropDownList ID="DDLEmployeeCreate" runat="server" Width="250px" OnSelectedIndexChanged="DDLEmployeeCreate_SelectedIndexChanged"
                            AutoPostBack="True" OnInit="DDLEmployeeCreate_Init" OnTextChanged="DDLEmployeeCreate_TextChanged" />
                    </td>
                </tr>
                <tr>
                    <td class="tableCSS" style="width: 180px;" align="right">
                        Office :
                    </td>
                    <td class="tableCSS">
                        <asp:DropDownList ID="DDLOfficeCreate" runat="server" Width="250px" OnSelectedIndexChanged="DDLOfficeCreate_SelectedIndexChanged"
                            AutoPostBack="True" />
                    </td>
                </tr>
                <tr>
                    <td class="tableCSS" style="width: 180px;" align="right">
                    </td>
                    <td class="tableCSS" align="right">
                        <asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
                    </td>
                </tr>
            </table>
<asp:Panel ID="pSuccesMessage" runat="server" style="background-color:Gray; display:none;">
            <p style="padding:20px;text-align:center; vertical-align:middle;color:Black;">
            Registration was successfully added!
            </p>
            <div style="padding: 10px; vertical-align: middle" align="center">
            <asp:Button ID="btnOK" runat="server" Text="Ok"/>
            </div>     
            </asp:Panel>
            <asp:ModalPopupExtender ID="mpeSuccess" runat="server"
                PopupControlID="pSuccesMessage"
                TargetControlID="btnAdd" 
                BackgroundCssClass="modalBackground" 
                OkControlID="btnOK"
                OnOkScript="HideModalPopupSuccess()">
            </asp:ModalPopupExtender>
            <asp:GridView ID="gvAtribut" runat="server" AllowPaging="True" AllowSorting="True"
                CellPadding="4" DataKeyNames="ID" DataSourceID="sdsAtribute" ForeColor="#333333"
                GridLines="None" DataMember="DefaultView" AutoGenerateColumns="False" Width="100%">
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <Columns>
                    <asp:CommandField ShowDeleteButton="True" ButtonType="Image" DeleteImageUrl="~/Styles/delete-img.png" />
                    <asp:BoundField DataField="ID" ReadOnly="True" Visible="False" />
                    <asp:BoundField DataField="EmployeeName" HeaderText="Name" ReadOnly="True"
                        SortExpression="[Employee].[EmployeeName]" />
                    <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="[Employee].[Email]" />
                    <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="[PhoneCard].[Phone]" />
                    <asp:BoundField DataField="InternPhone" HeaderText="int. Phone" SortExpression="[PhoneCard].[InternPhone]" />
                    <asp:BoundField DataField="WorkerMobile" HeaderText="Mobile" SortExpression="[Employee].[WorkerMobile]" />
                    <asp:BoundField DataField="NrOffice" HeaderText="Office" SortExpression="[Office].[NrOffice]" />
                </Columns>
                <EditRowStyle BackColor="#999999" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Height="50px" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#E9E7E2" />
                <SortedAscendingHeaderStyle BackColor="#506C8C" />
                <SortedDescendingCellStyle BackColor="#FFFDF8" />
                <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
            </asp:GridView>
            <asp:SqlDataSource ID="sdsAtribute" runat="server" ConnectionString="<%$ ConnectionStrings:ContactDataConnectionString %>"
                SelectCommand="SELECT [AtributPhone].[ID],[Employee].[EmployeeName], [Employee].[Email], [PhoneCard].[Phone], [PhoneCard].[InternPhone], [Employee].[WorkerMobile], [Office].[NrOffice] FROM [AtributPhone], [Employee], [PhoneCard], [Office] WHERE [AtributPhone].[ID_Phone] = [PhoneCard].[ID] AND [AtributPhone].[ID_Employee] = [Employee].[ID] AND [AtributPhone].[ID_Office] = [Office].[ID] ORDER BY [Employee].[EmployeeName] ASC"
                DeleteCommand="DELETE FROM AtributPhone WHERE (ID = @ID)"></asp:SqlDataSource>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="DDLInstitutionCreate" EventName="SelectedIndexChanged" />
            <asp:AsyncPostBackTrigger ControlID="DDLPhoneCreate" EventName="SelectedIndexChanged" />
            <asp:AsyncPostBackTrigger ControlID="DDLSubCategoryCreate" EventName="SelectedIndexChanged" />
            <asp:AsyncPostBackTrigger ControlID="DDLEmployeeCreate" EventName="SelectedIndexChanged" />
            <asp:AsyncPostBackTrigger ControlID="DDLOfficeCreate" EventName="SelectedIndexChanged" />
            <asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
</asp:Content>
4

1 回答 1

0

这里没有问题,但这应该可以帮助您入门。

试试这个:http ://www.aspdotnet-suresh.com/2011/03/how-to-show-modalpopup-to-edit-gridview.html

于 2013-01-03T14:59:02.047 回答