The name 'UserName' does not exist in the current context"?

Discussion in 'ASP .Net' started by =?Utf-8?B?TWljaGFlbA==?=, Oct 26, 2006.

  1. Hi, I am getting a strange error. Last night when I left work this was
    working perfectly. This morning when I try to run this code in VS2005, it
    comes up with an error saying "The name 'UserName' does not exist in the
    current context". I don't know what to do about it. The field is there. It
    worked yesterday. Any ideas?


    HTML CODE:
    <%@ Master Language="C#" EnableTheming="false"
    AutoEventWireup="true" CodeFile="mp_Main.master.cs" Inherits="mp_Main" %>

    <!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>My Page</title>
    <link rel="stylesheet" type="text/css" href="CSS/g-styles.css" />
    </head>
    <body>
    <form id="frmMain" runat="server">
    <asp:SiteMapDataSource ID="dsMySiteMap" runat="server"
    ShowStartingNode="False" SiteMapProvider="MainMapProvider" />
    <div id="g-wrapper">
    <div id="h-wrapper">
    <div id="h-head">
    <div class="l-area">
    <div class="l-column">
    <div class="f-label">user name</div>
    <div class="r-field" id="Div1">
    <div class="f-field-left"></div>
    <div class="f-field-center">
    <asp:TextBox ID="UserName" runat="server"
    CssClass="f-field"></asp:TextBox>
    </div>
    <div class="f-field-right"></div>
    </div>
    etc...

    CODE BEHIND:
    ....
    protected void btnLogin_Click(object sender, EventArgs e)
    {
    string sError = "";

    if (UserName.Text == "")
    {
    sError = "True";
    }
    etc...


    Thanks,
    Michael
     
    =?Utf-8?B?TWljaGFlbA==?=, Oct 26, 2006
    #1
    1. Advertising

  2. There are a couple issues that could be happening. It could be that the
    build of the page/site has failed without you knowing it so therefore when
    it's executing the code the object isn't getting connected properly because
    it doesn't know about it really (since the build process failed). Give a
    quick rebuild and see if any errors pop up

    Another thing could be the designer.cs file didn't update with the
    information on the protected members (in the web application project).

    See if it's able to work with this.UserName. Perhaps it's getting it
    confused with a username property that could be available in one of the
    namespaces (this one's a shot in the dark though).

    --
    Hope this helps,
    Mark Fitzpatrick
    Former Microsoft FrontPage MVP 199?-2006


    "Michael" <> wrote in message
    news:...
    > Hi, I am getting a strange error. Last night when I left work this was
    > working perfectly. This morning when I try to run this code in VS2005, it
    > comes up with an error saying "The name 'UserName' does not exist in the
    > current context". I don't know what to do about it. The field is there.
    > It
    > worked yesterday. Any ideas?
    >
    >
    > HTML CODE:
    > <%@ Master Language="C#" EnableTheming="false"
    > AutoEventWireup="true" CodeFile="mp_Main.master.cs" Inherits="mp_Main" %>
    >
    > <!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>My Page</title>
    > <link rel="stylesheet" type="text/css" href="CSS/g-styles.css" />
    > </head>
    > <body>
    > <form id="frmMain" runat="server">
    > <asp:SiteMapDataSource ID="dsMySiteMap" runat="server"
    > ShowStartingNode="False" SiteMapProvider="MainMapProvider" />
    > <div id="g-wrapper">
    > <div id="h-wrapper">
    > <div id="h-head">
    > <div class="l-area">
    > <div class="l-column">
    > <div class="f-label">user name</div>
    > <div class="r-field" id="Div1">
    > <div class="f-field-left"></div>
    > <div class="f-field-center">
    > <asp:TextBox ID="UserName" runat="server"
    > CssClass="f-field"></asp:TextBox>
    > </div>
    > <div class="f-field-right"></div>
    > </div>
    > etc...
    >
    > CODE BEHIND:
    > ...
    > protected void btnLogin_Click(object sender, EventArgs e)
    > {
    > string sError = "";
    >
    > if (UserName.Text == "")
    > {
    > sError = "True";
    > }
    > etc...
    >
    >
    > Thanks,
    > Michael
     
    Mark Fitzpatrick, Oct 26, 2006
    #2
    1. Advertising

  3. Mark,
    thank you for the reply. First I cannot build the project without hitting
    the error. The only way I have been able to build it is to comment out my
    code. If I run the application in debug mode, and then when I get the error
    just say to run the last good build I just say yes, it runs fine and also
    hits all my new code as well as runs fine through the code that is suppose to
    be giving the error. hmmm
    Secondly, I tried what you said about the "this.UserName" but it did not
    make any difference.

    Any other thoughts?
    Michael.

    "Mark Fitzpatrick" wrote:

    > There are a couple issues that could be happening. It could be that the
    > build of the page/site has failed without you knowing it so therefore when
    > it's executing the code the object isn't getting connected properly because
    > it doesn't know about it really (since the build process failed). Give a
    > quick rebuild and see if any errors pop up
    >
    > Another thing could be the designer.cs file didn't update with the
    > information on the protected members (in the web application project).
    >
    > See if it's able to work with this.UserName. Perhaps it's getting it
    > confused with a username property that could be available in one of the
    > namespaces (this one's a shot in the dark though).
    >
    > --
    > Hope this helps,
    > Mark Fitzpatrick
    > Former Microsoft FrontPage MVP 199?-2006
    >
    >
    > "Michael" <> wrote in message
    > news:...
    > > Hi, I am getting a strange error. Last night when I left work this was
    > > working perfectly. This morning when I try to run this code in VS2005, it
    > > comes up with an error saying "The name 'UserName' does not exist in the
    > > current context". I don't know what to do about it. The field is there.
    > > It
    > > worked yesterday. Any ideas?
    > >
    > >
    > > HTML CODE:
    > > <%@ Master Language="C#" EnableTheming="false"
    > > AutoEventWireup="true" CodeFile="mp_Main.master.cs" Inherits="mp_Main" %>
    > >
    > > <!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>My Page</title>
    > > <link rel="stylesheet" type="text/css" href="CSS/g-styles.css" />
    > > </head>
    > > <body>
    > > <form id="frmMain" runat="server">
    > > <asp:SiteMapDataSource ID="dsMySiteMap" runat="server"
    > > ShowStartingNode="False" SiteMapProvider="MainMapProvider" />
    > > <div id="g-wrapper">
    > > <div id="h-wrapper">
    > > <div id="h-head">
    > > <div class="l-area">
    > > <div class="l-column">
    > > <div class="f-label">user name</div>
    > > <div class="r-field" id="Div1">
    > > <div class="f-field-left"></div>
    > > <div class="f-field-center">
    > > <asp:TextBox ID="UserName" runat="server"
    > > CssClass="f-field"></asp:TextBox>
    > > </div>
    > > <div class="f-field-right"></div>
    > > </div>
    > > etc...
    > >
    > > CODE BEHIND:
    > > ...
    > > protected void btnLogin_Click(object sender, EventArgs e)
    > > {
    > > string sError = "";
    > >
    > > if (UserName.Text == "")
    > > {
    > > sError = "True";
    > > }
    > > etc...
    > >
    > >
    > > Thanks,
    > > Michael

    >
    >
    >
     
    =?Utf-8?B?TWljaGFlbA==?=, Oct 26, 2006
    #3
  4. Something else to try, open the master page, then switch back to design view
    from html view. VS.Net has the nasty habbit of not noticing controls until
    the page has been put into design view. Sometimes just toggling between the
    views adds the appropriate reference and it will then work.

    --
    Hope this helps,
    Mark Fitzpatrick
    Former Microsoft FrontPage MVP 199?-2006





    "Michael" <> wrote in message
    news:...
    > Mark,
    > thank you for the reply. First I cannot build the project without hitting
    > the error. The only way I have been able to build it is to comment out my
    > code. If I run the application in debug mode, and then when I get the
    > error
    > just say to run the last good build I just say yes, it runs fine and also
    > hits all my new code as well as runs fine through the code that is suppose
    > to
    > be giving the error. hmmm
    > Secondly, I tried what you said about the "this.UserName" but it did not
    > make any difference.
    >
    > Any other thoughts?
    > Michael.
    >
    > "Mark Fitzpatrick" wrote:
    >
    >> There are a couple issues that could be happening. It could be that the
    >> build of the page/site has failed without you knowing it so therefore
    >> when
    >> it's executing the code the object isn't getting connected properly
    >> because
    >> it doesn't know about it really (since the build process failed). Give a
    >> quick rebuild and see if any errors pop up
    >>
    >> Another thing could be the designer.cs file didn't update with the
    >> information on the protected members (in the web application project).
    >>
    >> See if it's able to work with this.UserName. Perhaps it's getting it
    >> confused with a username property that could be available in one of the
    >> namespaces (this one's a shot in the dark though).
    >>
    >> --
    >> Hope this helps,
    >> Mark Fitzpatrick
    >> Former Microsoft FrontPage MVP 199?-2006
    >>
    >>
    >> "Michael" <> wrote in message
    >> news:...
    >> > Hi, I am getting a strange error. Last night when I left work this was
    >> > working perfectly. This morning when I try to run this code in VS2005,
    >> > it
    >> > comes up with an error saying "The name 'UserName' does not exist in
    >> > the
    >> > current context". I don't know what to do about it. The field is
    >> > there.
    >> > It
    >> > worked yesterday. Any ideas?
    >> >
    >> >
    >> > HTML CODE:
    >> > <%@ Master Language="C#" EnableTheming="false"
    >> > AutoEventWireup="true" CodeFile="mp_Main.master.cs" Inherits="mp_Main"
    >> > %>
    >> >
    >> > <!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>My Page</title>
    >> > <link rel="stylesheet" type="text/css" href="CSS/g-styles.css" />
    >> > </head>
    >> > <body>
    >> > <form id="frmMain" runat="server">
    >> > <asp:SiteMapDataSource ID="dsMySiteMap" runat="server"
    >> > ShowStartingNode="False" SiteMapProvider="MainMapProvider" />
    >> > <div id="g-wrapper">
    >> > <div id="h-wrapper">
    >> > <div id="h-head">
    >> > <div class="l-area">
    >> > <div class="l-column">
    >> > <div class="f-label">user name</div>
    >> > <div class="r-field" id="Div1">
    >> > <div class="f-field-left"></div>
    >> > <div class="f-field-center">
    >> > <asp:TextBox ID="UserName" runat="server"
    >> > CssClass="f-field"></asp:TextBox>
    >> > </div>
    >> > <div class="f-field-right"></div>
    >> > </div>
    >> > etc...
    >> >
    >> > CODE BEHIND:
    >> > ...
    >> > protected void btnLogin_Click(object sender, EventArgs e)
    >> > {
    >> > string sError = "";
    >> >
    >> > if (UserName.Text == "")
    >> > {
    >> > sError = "True";
    >> > }
    >> > etc...
    >> >
    >> >
    >> > Thanks,
    >> > Michael

    >>
    >>
    >>
     
    Mark Fitzpatrick, Oct 26, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arjen
    Replies:
    1
    Views:
    9,777
    =?Utf-8?B?RGF2aWQgSmVzc2Vl?=
    Aug 21, 2006
  2. J055
    Replies:
    3
    Views:
    3,457
  3. Montand
    Replies:
    1
    Views:
    560
    Alexey Smirnov
    Feb 20, 2008
  4. Peter Morris
    Replies:
    2
    Views:
    6,665
    Peter Morris
    Mar 17, 2008
  5. avecreep
    Replies:
    0
    Views:
    577
    avecreep
    Aug 5, 2008
Loading...

Share This Page