0

好的。因此,我有一个简单的网站,其中包含用户名和密码文本框以及 vb2008 中的提交按钮,该按钮应该指向一个新页面,该页面访问网格视图中的 SQL 源表。我应该输入“mcobery”作为用户名,输入“password”作为密码,当我这样做时,什么也没有发生。我后面的代码有问题吗?

看看我背后的代码以及我的默认页面和它指向代码的页面。

这是后面的代码

 Protected Sub butSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles    butSubmit.Click

    Dim correctPassword As Boolean = False

    'Establish the SqlConnection by using the configuration manager to get the connection string in our web.config file.

    Using mySqlConnection = New Data.SqlClient.SqlConnection  (ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

        Dim sql As String = "SELECT password FROM MyUsers WHERE username = @userName"

        Using mySqlCommand = New Data.SqlClient.SqlCommand(sql, mySqlConnection)
            mySqlCommand.Parameters.AddWithValue("@userName", Me.TextBox1.Text)

            Try
                mySqlConnection.Open()

                Using myReader = mySqlCommand.ExecuteReader()

                    If myReader.Read() Then

                        Dim password As String = myReader.GetString(myReader.GetOrdinal("password"))

                        If password = Me.TextBox2.Text Then

                            'Open page with users and roles

                            correctPassword = True

                        End If

                    End If

                End Using

            Catch ex As Exception
                Console.WriteLine(ex.ToString())

            End Try

        End Using

    End Using

    If correctPassword Then

        Response.Redirect("userAdmin.aspx")

    End If

   End Sub

  End Class

我的 default.aspx 页面

 <%@ Page Language="VB" Debug="true" MasterPageFile="~/master.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" title="Untitled Page" %>

 <asp:Content ID="Content1" ContentPlaceHolderID="header" Runat="Server">
<p style="text-align: center; color: white">
    SAM PEPPARD</p>
 </asp:Content>
 <asp:Content ID="Content2" ContentPlaceHolderID="navigation" Runat="Server">
<a href="Default.aspx">Default.aspx</a>
<br />
<br />
<a href="userAdmin.aspx">userAdmin.aspx</a>
<br />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="main" Runat="Server">
&nbsp &nbsp User Name
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
&nbsp&nbsp&nbsp&nbsp;&nbsp;&nbsp;&nbsp; Password&nbsp<asp:TextBox ID="TextBox2" 
    runat="server" TextMode="Password"></asp:TextBox>
    &nbsp&nbsp&nbsp&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="butSubmit" runat="server" Text="Submit" />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="footer" Runat="Server">
</asp:Content>

当您按下提交时它应该指向的页面。它被称为 userAdmin.aspx

<%@ Page Language="VB" MasterPageFile="~/master.master" AutoEventWireup="false" title="UserAdmin" %>

<asp:Content ID="Content1" ContentPlaceHolderID="header" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="navigation" Runat="Server">
<a href="Default.aspx">Default.aspx</a>
<br />
<br />
<a href="userAdmin.aspx">userAdmin.aspx</a>
<br />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="main" Runat="Server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    SelectCommand="SELECT * FROM [MyUsers]"></asp:SqlDataSource>
<asp:GridView ID="UserRolesGrid" runat="server" DataSourceID="SqlDataSource1" 
    Width="399px" AutoGenerateColumns="False" DataKeyNames="id">
    <Columns>
        <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" 
            ReadOnly="True" SortExpression="id" />
        <asp:BoundField DataField="user_logon_id" HeaderText="user_logon_id" 
            SortExpression="user_logon_id" />
        <asp:BoundField DataField="user_full_name" HeaderText="user_full_name" 
            SortExpression="user_full_name" />
        <asp:BoundField DataField="user_description" HeaderText="user_description" 
            SortExpression="user_description" />
        <asp:BoundField DataField="user_password" HeaderText="user_password" 
            SortExpression="user_password" />
    </Columns>
</asp:GridView>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="footer" Runat="Server">
</asp:Content>

如果有帮助,这里是母版页代码

<%@ Master Language="VB" CodeFile="master.master.vb" Inherits="master" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0   Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Website 1</title>
<style type="text/css">
    .fullHW
    {
        width: 100%;
        height: 100%;
    }
    .fullW
    {
        width: 100%;
    }
    .header
    {
        color:black;
        background-color:indigo;
        height: 100px;
        font-size:16.0pt;
        font-family:"Arial","sans-serif";
    }
    .footer
    {
        color:white;
        background-color:indigo;
        height: 100px;
        font-size:8.0pt;
        font-family:"Arial","sans-serif";
    }
    .nav
    {
        background-color:black;
        width: 200px;
        height: 400px;
        font-size:11.0pt;
        color:black;
        font-family:"Arial","sans-serif";
    }
    .content
    {
        background-color:white;
        height: 100%;
        font-size:11.0pt;
        color:black;
        font-family:"Arial","sans-serif";
    }

    a:link              { color:white; text-decoration:none; }
    a:visited           { color:white; text-decoration:none; }
    a:hover             { color:white; text-decoration:none; }
    a:active            { color:white; text-decoration:none; }


</style>
</head>
<body>
<form id="form1" runat="server">
<div class="fullHW">
    <table border="0" cellpadding="0" cellspacing="0" class="fullHW">
        <tr class="fullHW">
          <td class="header">
            <asp:ContentPlaceHolder ID="header" runat="server">
            </asp:ContentPlaceHolder>
          </td>
        </tr>
        <tr class="fullHW">
          <td>
            <table border="0" cellpadding="0" cellspacing="0" class="fullHW">
              <tr class="fullHW">
                <td class="nav">
                  <asp:ContentPlaceHolder ID="navigation" runat="server">
                     <a href="Default.aspx">Default.aspx</a>

                      <br />
                      <br />

                     <a href="userAdmin.aspx">userAdmin.aspx</a>
                  </asp:ContentPlaceHolder>
                </td>
                <td class="content">
                  <asp:ContentPlaceHolder ID="main" runat="server">
                  </asp:ContentPlaceHolder>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr class="fullHW">
            <td class="footer">
                <asp:ContentPlaceHolder ID="footer" runat="server">
                </asp:ContentPlaceHolder>
            </td>
        </tr>
    </table>
  </div>
 </form>
 </body>
 </html>
4

1 回答 1

0

我没有看到您将btnSubmit_Click方法与btnSubmit按钮相关联。Page_Load我想你可以在检查后处理处理程序中的提交单击按钮IsPostBack

于 2013-03-02T05:10:10.783 回答