Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

The name 'txtbxUserName' does not exist in the current context

$
0
0

I have a web forms app that will not run, and returns the above error. The thing is that the textbox does exist, and has the ID='txtbxUserName'.

Login.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="identityDemoApp.Login" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title></head><body><form id="form1" runat="server"><div><h4 style="font-size: medium">Log In</h4><hr /><div><asp:Literal runat="server" ID="litErrorMsg" Text="Invalid username or password." Visible="false" /></div><div style="margin-bottom: 10px"><asp:Label runat="server" AssociatedControlID="txtbxUserName">User name</asp:Label><br /><asp:TextBox runat="server" ID="txtbxUserName"  /></div><div style="margin-bottom: 10px"><asp:Label runat="server" AssociatedControlID="txtbxPassword">Password</asp:Label><br /><asp:TextBox runat="server" ID="txtbxPassword" TextMode="Password" /></div><div style="margin-bottom: 10px"><asp:Button ID="btnSignIn" runat="server" Text="Log in" OnClick="btnSignIn_Click" /><a href="Register.aspx">New User</a></div></div></form></body></html>

C#  code behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.AspNet.Identity;
using Microsoft.Owin.Security;
//using Microsoft.AspNet.WebApi.Owin;

namespace IdentityDemo
{
    public partial class Login : System.Web.UI.Page
    {


        protected void btnSignIn_Click(object sender, EventArgs e)
        {
            var userStore = new UserStore<IdentityUser > ();
            var userManager = new UserManager<IdentityUser > (userStore);
            var user = userManager.Find(txtbxUserName.Text, txtbxPassword.Text);

            if (user != null)
            {
                var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
                var userIdentity = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);

                authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, userIdentity);

                if (Request.QueryString["ReturnUrl"] == null)
                    Response.Redirect("~/Secured/Home.aspx");
            }
            else
            {
                litErrorMsg.Visible = true;
            }
        }
    }
}

I don't see why this errors.


Viewing all articles
Browse latest Browse all 4737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>