Link to home
Start Free TrialLog in
Avatar of patd1
patd1Flag for United States of America

asked on

Cant find a label control in the code behind

I have default.aspx page and default.aspx.cs page. I just added a label (UserName) to my default.aspx page and tried to set the text of that label in the page_load method in the code behind. I get a compilation error: UserName does not exist in the current context. This seems to be the simplest change but is not working. Please check my code and advise change.

Thank You.

<%@ Page Language="C#" MasterPageFile="MyMaster.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" EnableViewState="true" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit"%>

<div id="simple">
                                <table>
                                    <tr>
                                        <td>
                                            <asp:Panel ID="panelSimple" CssClass="float_left" runat="server" GroupingText="User"
                                                EnableViewState="false">
                                                <table>
                                                <tr>
                                                <td>
                                                    User Name: <asp:Label ID = "UserName" runat = "server"></asp:Label>
                                                </td>
</tr>
...
</table>
</Panle>
..
...
</td>
</tr>
</table>
</div>

Open in new window


public partial class _Default : MyUserInformation
{
protected void Page_Load(object sender, EventArgs e)
    {
        string UserRole = this.MuUserRole;
        UserName.Text = this.MyUserRole;
        //this.UserName.Text = this.MyUserRole;

...

}

}

Open in new window

Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Make sure your Default.aspx.designer.cs file has something like this in it:

        /// <summary>
        /// UserName control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.Label UserName;
ASKER CERTIFIED SOLUTION
Avatar of JosephEricDavis
JosephEricDavis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of patd1

ASKER

Thank for your reply. I just noticed that there were two defaults in solution. I deleted one and it works now.

Thank You.
Avatar of JosephEricDavis
JosephEricDavis

Are you going to close this question?