Results 1 to 3 of 3

Thread: My ASP label not displaying

  1. #1
    Join Date
    Jun 2008
    Posts
    107
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default My ASP label not displaying

    Hello,

    Please have a look at my VB/ASP code and tell me if you can see what's wrong (I have bolded the important segments):

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
    
    "http://www.w3.org/TR/html4/strict.dtd">
    
    <%@Page Explicit="true" Language="VB" Debug="true" 
    
    Autoeventwireup="false" EnableSessionState="False" 
    
    EnableViewState="False" %>
    <%@ Import Namespace="System.Web.Mail" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="MySql.Data.MySqlClient" %>
    
    <html>
    
    <head>
    <title>Autobody</title>
    </head>
    
    <script runat="server">
    
    Dim Connection As MySqlConnection
    Dim MDA As MySqlDataAdapter
    Dim DS As DataSet
    
    
    Sub Page_Load(sender As Object, e As EventArgs)
    
    	username_textbox.Text = String.Empty
    	password_textbox.Text = String.Empty
    	feedback_label.Text = "feedback"
    
    End Sub
    
    
    Function Connect() As String
    
        	Dim ConStr As String = "server=localhost; user id=gib; 
    
    password=gibpw; database=autobody;"
    
    	Connection = New MySqlConnection(ConStr)
    	MDA = new MySqlDataAdapter()
    	DS = new DataSet()
    	Connection.open()
    
    	Return "OK"
    
    End Function
    
    
    Function Disconnect() As String
    
    	Connection.close()
    	Return "OK"
    
    End Function
    
    
    Sub SubmitButton_Clicked(Sender As Object, E As EventArgs)
    
    	If Not (Connect() = "OK") Then
    		feedback_label.Text = "Error connecting"
    		Return
    	End If
    
    	FillDataSet()
    
    	If Not (Disconnect() = "OK") Then
    		feedback_label.Text = "Error disconnecting"
    		Return
    	End If
    
    	Authenticate()
    		 
    End Sub
    
    
    Sub FillDataSet()
    
    	Dim Command As New MySqlCommand
    	Dim Query As String
    
    	Query = "SELECT * FROM CLIENTS;"
    	Command.Connection = Connection
    	Command.CommandText = Query
    	MDA.SelectCommand = Command
    	MDA.Fill(DS)
    	MDA.dispose()
    	Command.dispose()
    
    End Sub
    
    
    Sub Authenticate()
    
    	Dim username As String
    	Dim password As String
    	Dim i As Integer
    
    	For i = DS.Tables(0).Rows.Count-1 to 0 Step -1
    		username = DS.Tables(0).Rows(i).Item("username")
    		If username = username_textbox.Text.Trim() Then
    			password = 
    
    DS.Tables(0).Rows(i).Item("password")
    			If password = password_textbox.Text Then
    				
    
    Response.Redirect("access_granted.html")
    			Else Exit For
    			End If
    		End If
    	Next
    
    	feedback_label.Text = "Access denied"
    
    End Sub
    
    </script>
    
    <body>
    
    <form runat="server">
    <table cellpadding=0 cellspacing=0 border=1>
    <tr><td colspan=2>Please log in:</td></tr>
    <tr>
    <td>Username:</td>
    <td style="width: 200px;"><asp:textbox style="width: 200px;" 
    
    id="username_textbox" text="" runat="server"/></td>
    </tr>
    <tr>
    <td>Password:</td>
    <td style="width: 200px;"><asp:textbox style="width: 200px;" 
    
    id="password_textbox" text="" textmode="password" 
    
    runat="server"/></td>
    </tr>
    <tr><td colspan=2><asp:button id="login_button" text="login" 
    
    onclick="SubmitButton_Clicked" runat="server" /></td></tr>
    <tr><td colspan=2><asp:label id="feedback_label" ForeColor="red"  
    
    runat="server" /></td></tr>
    </table>
    <!-- AutoPostBack=true -->
    </form>
    
    </body>
    
    </html>
    Basically, I'm trying to get the Page_Load subroutine to execute on the page load, but it doesn't seem to be called. I'm assuming that because I set my feedback label to "feedback" in the Page_Load subroutine, I should see it displayed on the page saying "feedback" on first loading the page and every time I refresh. But this doesn't happen. I'm lead to conclude that the Page_Load subroutine is not being called on the page load.

    Can anyone tell why?

    You can view the site at: http://www.shahspace.com/autobody/index.aspx

    Thanks for your help.

  2. #2
    Join Date
    Feb 2011
    Posts
    16
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    seems to be working when I tested the sample link

    "Access Denied" appeared in red, replacing the text label "feedback"

  3. #3
    Join Date
    Feb 2011
    Location
    Switzerland
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi

    If I use username "test" password "1234" and press OK, the label "feedback" goes into "Access denied".

    Please explain what you need.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •