C# 用于按钮保存的模式弹出式AJAX扩展

C# 用于按钮保存的模式弹出式AJAX扩展,c#,asp.net,ajax,modalpopup,C#,Asp.net,Ajax,Modalpopup,我有一个按钮,可以在数据库中保存记录,但希望用户按下该按钮以获得注册成功的通知,在另一种情况下,该按钮将被告知存在此类注册。使用模式弹出扩展插件(AJAX)可以做到这一点 此功能可以在asp.net C中完成# 这是服务器端的代码 protected void btnAdd_Click(object sender, EventArgs e) { if (!DALAtribut.CheckId("SELECT * FROM AtributPhone WHER

我有一个按钮,可以在数据库中保存记录,但希望用户按下该按钮以获得注册成功的通知,在另一种情况下,该按钮将被告知存在此类注册。使用模式弹出扩展插件(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>

函数showmodalpopupsucess(){
var modal=$find('mpeSuccess');
modal.show();
}
函数HideModalPopupSuccess(){
var modal=$find('mpeSuccess');
modal.hide();
}
功能fnClickSuccess(发件人,e){
__doPostBack(发送方,e);
}
机构:
电话:
第节:
雇员:
办公室:

注册已成功添加!


这里没有问题,但这应该可以帮助您开始


试试这个:

问题是什么?到目前为止,您尝试了什么?您遇到了什么问题?客户端事件没有在服务器上传输,也没有在服务器上处理。没有问题,如果这对您有帮助,请检查它是否是答案。