locked
Displaying Session Username when logged in RRS feed

  • Question

  • User-1138267494 posted

     I want to display username in master page... default  controlid visible false..

    Attempt1:

    if (Session["UserType"]!= null)
    {
     Page.Master.FindControl("panel_UserName").Visible = true; //Working fine
    
    }

    Attempt2:

    if (Session["UserType"]!= null)
     {
     ((Panel)Page.Master.FindControl("panel_UserName")).InnerText = " Welcome " + Session["UserName"].ToString();
     }
               

    Error display like : 'System.Web.UI.WebControls.Panel' does not contain a definition for 'InnerText' and no extension method

    How to display username in masterpage...if UserType==true

    Friday, April 26, 2013 8:20 AM

Answers

  • User166892907 posted

    ((Label) Page.Master.FindControl("lbl_UserName")).Text = " Welcome " + Session["UserName"].ToString();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 26, 2013 8:53 AM

All replies

  • User166892907 posted

    add an asp:Label in your panel panel_UserName

    Panel pUserName = (Panel)Page.Master.FindControl("panel_UserName");
    Label lbUserName = (Label)Panel.FindControl("label_UserName");
    lbUserName.Text = " Welcome......



    Friday, April 26, 2013 8:26 AM
  • User551462331 posted

    try this

    if (Session["UserType"]!= null) 
     { 
     ((Panel)Page.Master.FindControl("panel_UserName")).Text = " Welcome " + Session["UserName"].ToString(); 
     } 
    

    It should have been Text instead of InnerText...

    hope this helps...

    Friday, April 26, 2013 8:27 AM
  • User-42918493 posted

    Put one label inside that panel....

    Page.Master.FindControl("Label1").Text = " Welcome " + Session["UserName"].ToString();



    Friday, April 26, 2013 8:28 AM
  • User-1138267494 posted

    Attempt 3:

    if (Session["UserType"]!= null)
     {
     ((Panel)Page.Master.FindControl("panel_UserName")).Text = " Welcome " + Session["UserName"].ToString();
     }
     

    Attempt4:

    I have added label control inside panel

     Page.Master.FindControl("lbl_UserName").Text = " Welcome " + Session["UserName"].ToString();


    Error Shows: 'System.Web.UI.Control' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'System.Web.UI.Control' could be found (are you missing a using directive or an assembly reference?)

    Friday, April 26, 2013 8:52 AM
  • User166892907 posted

    ((Label) Page.Master.FindControl("lbl_UserName")).Text = " Welcome " + Session["UserName"].ToString();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 26, 2013 8:53 AM
  • User-1138267494 posted

    Thanks Maire its Working fine.....

    Friday, April 26, 2013 8:59 AM