Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using a login control and am having issues with Firefox wanting to display a username <asp:LoginName ID="HeadLoginName" in my LoggedInTemplate (which will always be an email address) as a mailto: element. IE renders it as just text with my css styles.

http://img338.imageshack.us/img338/7276/loginview.jpg[^]

How can I prevent Firefox from rendering the username as an email address? Or, how can I truncate the displayed user name (everything including and after the @) using substring() and IndexOf() embedded in the aspx page?


I have tried:

C#
protected void Page_Load(object sender, EventArgs e)
{
    string username = this.User.Identity.Name;
    username = changeTheName(username);
    HeadLoginName.FormatString = "Welcome, " + username;
}
private string changeTheName(string username)
{
    //make changes:
    return username.Substring(0, username.IndexOf('@'));
}


but the .cs file does not know the HeadLoginName control exists.

C:\Web\Site.Master.cs(13,32): error CS1061: 'SiteMaster' does not contain a definition for 'User' and no extension method 'User' accepting a first argument of type 'SiteMaster' could be found (are you missing a using directive or an assembly reference?)
C:\Web\Site.Master.cs(15,9): error CS0103: The name 'HeadLoginName' does not exist in the current context


My problem seems to be that I cannot access the HeadLoginName control from the Page_Load .cs file (Site.Master).


<<<<<<<<<<UPDATE>>>>>>>>>>
This is what I found to work:

C#
protected void Page_Load(object sender, EventArgs e)
{
    string username = HttpContext.Current.User.Identity.Name;
    username = changeTheName(username);

    LoginName loginName = HeadLoginView.FindControl("HeadLoginName") as LoginName;

    if(loginName != null)
        loginName.FormatString = "Welcome, " + username;
}
private string changeTheName(string username)
{
    //make changes:
    return username.Substring(0, username.IndexOf('@'));
}


Thanks.
Posted
Updated 13-Nov-10 11:33am
v6

The control that is responsible for displaying the user name is <asp:loginname runat="server" id="HeadLoginName /><br mode=" hold=" /><br mode=" which="" means="" that="" it="" displays="" the="" username="" mode="hold" xmlns:asp="#unknown">You can assign this property on your server side.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
namespace CodeProjectWeb
{
    public partial class mypage: System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string username = this.User.Identity.Name;
            username = changeTheName(username);
            HeadLoginName.FormatString = "Welcome, " + username;
        }
        private string changeTheName(string username)
        {
            //make your changes:
            return "username changed";
        }
    }

}
Good luck.
 
Share this answer
 
Comments
willworknow1 13-Nov-10 15:00pm    
I have tried something like this but get this error stating that the .cs file does know anything about the control:

C:\Web\Site.Master.cs(13,32): error CS1061: 'SiteMaster' does not contain a definition for 'User' and no extension method 'User' accepting a first argument of type 'SiteMaster' could be found (are you missing a using directive or an assembly reference?)
C:\Web\Site.Master.cs(15,9): error CS0103: The name 'HeadLoginName' does not exist in the current context
Ed Guzman 13-Nov-10 17:31pm    
it means that you have to add:
using System.Web.Security;
Just a wild guess:

Could it be that you installed some kind of Firefox Add-on that makes e-mail addresses and links in plain text clickable?

Cheers
Uwe
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900