2013-03-02 108 views
0

好的。所以我有一个简单的网站,其中包含一个用户名和密码文本框以及vb2008中的提交按钮,该按钮应该导致访问网格视图中SQL源表的新页面。我应该输入“mcobery”作为用户名和“密码”作为密码,当我这样做时,没有任何反应。我的代码背后有什么问题吗?我的用户名和登录页面不起作用

看看我的代码以及我的默认页面和它导致代码的页面。

这背后

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> 

回答

0

我没有看到你的关联方法btnSubmit_ClickbtnSubmit按钮。 我想你可以在检查IsPostBack后处理Page_Load处理程序中的提交点​​击按钮。