ASP.NET

Moderators: None (Apply to moderate this forum)
Number of threads: 1735
Number of posts: 3305

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
help with c#.net log in webform using ms access Posted by tricket_7 on 13 Aug 2012 at 8:14 AM
I am trying to build a simple login form on an existing website I am getting these errors:
txtUser does not exist in the current context
txtPass does not exist in the current context
Literal1 does not exist in the current context

I will paste below first the form, then the codebehind

form
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="logIn.aspx.cs" Inherits="WebApplication1._Default" %>

<!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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     New users can <a href="CarrierRegistration.aspx">register</a> here.<br />
   
    <table  border="0" style="border-width: 3px; border-color:#c2c2c2;
border-style: solid;">  
   <tr>
   <td></td>
   <td><strong>Please Login</strong></td></tr>
    <tr>
    <td>
        <asp:Label ID="lblUser" runat="server" Text="Username:"></asp:Label>
    </td>
    <td>
        <asp:TextBox ID="txtUser" runat="server"></asp:TextBox>
    </td></tr>
    <tr>
    <td>
        <asp:Label ID="lblPass" runat="server" Text="Password:"></asp:Label>
    </td>
    <td>
        <asp:TextBox ID="txtPass" runat="server"></asp:TextBox>
    </td></tr>
    <tr>
    <td></td>
    <td>
       
    </td></tr>
    <tr>
    <td></td>
    <td> <asp:Button ID="btnLogin" runat="server" Text="Login" 
            onclick="btnLogin_Click" /></td></tr>
    <tr>
    <td>
        <asp:Literal ID="Literal1" runat="server"></asp:Literal>
    </td></tr>
    
    </table>
    
    </div>
    </form>
</body>
</html>


Codebehind
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;


namespace WebApplication1
{
    

    public partial class _logIn : System.Web.UI.Page
    {
       

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            

            string connect = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\\Users\\Christie\\Desktop\\WebApplication1\\App_Data\\prosearchusers.mdb";
            string query = "Select Count(*) From tblCustRecords Where username = '" & txtUser & "' And [password] = '" & txtPass & "'";
            int result = 0;
            using (OleDbConnection conn = new OleDbConnection(connect))
            {
                using (OleDbCommand cmd = new OleDbCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("Cust_Name", txtUser);
                    cmd.Parameters.AddWithValue("Cust_Password", txtPass);
                    conn.Open();
                    Session["User"] = txtUser;
                    result = (int)cmd.ExecuteScalar();
                }
            }
            if (result > 0)
            {
                Response.Redirect("LoggedIn.aspx");
            }
            else
            {
                Literal1 = "Invalid login";
            }

        }
    }
}


Can someone please help me, I really do not have much experience in .net programming



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.