0

我有一个创建销售人员的工作页面,我使用了 AJAX,所以留在管理页面并加载创建页面,现在我的创建页面没有保存到数据库中。我没有收到任何错误,它根本无法保存。我是 AJAX 的新手,我确信我遗漏了一些东西,但我已经搜索了一段时间并且需要帮助。这是我的管理页面代码。

    <%@ Page Title="" Language="vb" AutoEventWireup="false"
MasterPageFile="~/Site.Master" CodeBehind="AdminPage.aspx.vb" Inherits="PyriteGoldPresentation.AdminPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script src="../Scripts/jquery-1.8.2.js" type="text/javascript"></script>
<script src="../Scripts/PyriteGoldAjax.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id = "Main">
    <input type="button" id="ViewAllUsers" value="View All Users" />
    <input type="button" id="AddItem" value = "Add Item" />
    <input type="button" id="CreateSalesAccount" value="Create A Sales Account" />
    <input type="button" id="ViewAllOrderHistory" value="View Order History" />
</div>
</asp:Content>

     Public Class AdminPage
Inherits System.Web.UI.Page

页面背后的代码。

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

End Class

这是我使用的 AJAX。

    $(document).ready(function () {
$('#CreateSalesAccount').click(function () {
    $.ajax({
        type: 'POST',
        url: "/admin/CreateSalesAccount.aspx",
        success: function (result) {
            var main = $('#Main');
            main.fadeTo('fast', .01);
            main.html($('#Main', result).html());
            main.fadeTo('fast', 1);
        }
    });
});
});

    <%@ Page Title="" Language="vb" AutoEventWireup="false"    MasterPageFile="~/Site.Master" CodeBehind="CreateSalesAccount.aspx.vb"  Inherits="PyriteGoldPresentation.CreateSalesAccount"%>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script src="../Scripts/jquery-1.8.2.js" type="text/javascript"></script>
<script src="../Scripts/PyriteGoldAjax.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div id="Main">
    <div style="width: 400px; margin-left:auto; margin-right:auto;">
        <div class="row">
            <h2>
                Create Sales Account
            </h2>
        </div>
        <div class="row">
            <span class="column1">
                <asp:Label ID="FirstNameLabel" runat="server" Text="First Name"/>
            </span>
            <span class="column2">
                <asp:TextBox ID="FirstNameTextField" runat="server" Width="137px"/>
            </span>
            <span class="column3">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"    ErrorMessage="*Required Field"
                 ControlToValidate="FirstNameTextField"/>
            </span>
        </div>
        <div class="row">
            <span class="column1">
                <asp:Label ID="LastNameLabel" runat="server" Text="Last Name"/>
            </span>
            <span class="column2">
                <asp:TextBox ID="LastNameTextBox" runat="server" Width="137px"/>
            </span>
            <span class="column3">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*Required Field" ControlToValidate="LastNameTextBox"/>
            </span>
        </div>
        <div class="row">
            <span class="column1">
                <asp:Label ID="EmailLabel" runat="server" Text="E-Mail Address"/>
            </span>
            <span class="column2">
                <asp:TextBox ID="EmailTextBox" runat="server" Width="134px"/>
            </span>
            <span class="column3">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*Required Field" ControlToValidate="EmailTextBox"/>
            </span>
        </div>
        <div class="row">
            <span class="column1">
                <asp:Label ID="VerifyEmailLabel" runat="server" Text="Verify E-Mail"/>
            </span>
            <span class="column2">
                <asp:TextBox ID="VerifyEmailTextBox" runat="server" Width="136px"/>
            </span>
            <span class="column3">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="*Required Field" ControlToValidate="VerifyEmailTextBox"/>
            </span>
        </div>
        <div class="row">
            <span class="column1">
                <asp:Label ID="PasswordLabel" runat="server" Text="Password"/>
            </span>
            <span class="column2">
                <asp:TextBox ID="PasswordTextBox" runat="server" Width="138px" 
                TextMode="Password"/>
            </span>
            <span class="column3">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="*Required Field" ControlToValidate="PasswordTextBox"/>
            </span>
        </div>
        <div class="row">
            <span class="column1">
                <asp:Label ID="VerifyPasswordLabel" runat="server" Text="Verify Password"/>
            </span>
            <span class="column2">
                <asp:TextBox ID="VerifyPasswordTextBox" runat="server" Width="138px" 
                TextMode="Password"/>
            </span>
            <span class="column3">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="*Required Field" ControlToValidate="VerifyPasswordTextBox"/>
            </span>
        </div>
        <div class="row" style="color:Red;">
            <asp:CompareValidator ID="EmailValidator" runat="server" ErrorMessage="**E- mail Feilds Must Match" ControlToCompare="EmailTextBox"  ControlToValidate="VerifyEmailTextBox"/><br />
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1"  runat="server" 
            ErrorMessage="**E-mail Addresses must follow the pattern user@domain.com"  ControlToValidate="EmailTextBox" 
            ValidationExpression="\w+([-+.']\w+[-]*)*@\w+([-.]*\w+)*\.\w+([-.]\w+)*"/> <br />
            <asp:CompareValidator ID="PasswordValidator" runat="server"  ErrorMessage="**Password Fields Must Match" ControlToCompare="PasswordTextBox"  ControlToValidate="VerifyPasswordTextBox"/>
        </div>
        <div>
            <asp:Button ID="SubmitButton" runat="server" Text="Submit" />
        </div>
    </div>
</div>
</asp:Content>

和背后的代码

    Imports PyriteGoldBLL
Imports PyriteGoldModel

Public Class CreateSalesAccount
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles  Me.Load
    If Session("permissionValue") <> 3 Then
        Response.Redirect("~/Home.aspx")
    End If
End Sub

Protected Sub SubmitButton_Click(sender As Object, e As EventArgs) Handles SubmitButton.Click
    Dim userLogic As New UserLogic()
    Dim user As New User()
    With user
        .FirstName = FirstNameTextField.Text
        .LastName = LastNameTextBox.Text
        .Email = EmailTextBox.Text
        .Password = PasswordTextBox.Text
        .Activated = True
        .Permission = 2
    End With
    userLogic.CreateUser(user)
End Sub
End Class
4

2 回答 2

0

您正在设置 Main div 的 html 内容。这不会将页面呈现为 asp 页面。因此,它不会为 SubmitButton 创建点击处理程序。它不会为 button 调用 click 事件。您必须为按钮添加 ajax 调用/表单标签才能发帖。

于 2012-10-24T14:43:54.257 回答
0

您有 AutoEventWireup="false" ,因此单击事件未连接到 SubmitButton_Click 方法。

添加 OnClick="SubmitButton_Click"

 <asp:Button ID="SubmitButton" runat="server" Text="Submit" />
于 2012-10-24T14:44:58.023 回答