1

I am making a Login Page with ASP.Net using C#... and i have put my html code in Login.aspx page . that contains a textbox named username but when I give reference of my textbox in Login.aspx.cs to make the validations on this text box ... as

if(string.IsNullOrEmpty(username.Text))
{
...
...
}

i am getting an error that is saying ...-"The 'username' doesn't exist in the current context"...... how can i get rid of this error .... it is making me mas .... Help will be appreciable towards this error ... please help me ....

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %> 
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> 
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
Tieson T.
  • 20,657
  • 5
  • 74
  • 89
Will
  • 43
  • 1
  • 7

1 Answers1

2

It depends on what you have taken.

If you have draged and droped ASP TextBox the automatically code has generated as:

<asp:TextBox ID="username" runat="server"></asp:TextBox>

which automatically contains runat="server"

But if you have taken HTML text box then code is as follows:

<input id="username" type="text" />

In this you will have to add the line on your own as runat="server"

It will look as follows:

<input id="username" type="text"  runat="server"/>

Then you can use it for serverside.

Hope its helpful.

Freelancer
  • 8,935
  • 7
  • 40
  • 80
  • Thanx...... Buddy .... it really helped me .... Thankz a lot ..... I am just a Beginner with you .... again thanx a lot – Will May 02 '13 at 05:36
  • @Will if answer is helpful, then you can accept this as a answer by ticking the checkbox. – Freelancer May 02 '13 at 05:41