Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 725
  • Last Modified:

master page in asp.net

i want when user login on page
user name will be display on master page lable


0
chandresh43
Asked:
chandresh43
  • 5
  • 5
  • 3
  • +1
1 Solution
 
informaniacCommented:
((Label)this.Master.FindControl("lblName")).Text = " Name";
0
 
carlnorrbomCommented:
Hi,

Or maybe simply just use the asp.net server control "LoginName"? Just place it somewhere in the markup of Your master page:

<asp:LoginName ID="LoginName1" runat="server" />

/Carl.
0
 
chandresh43Author Commented:
this give me error
 Object reference not set to an instance of an object.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
chandresh43Author Commented:
and my login page in not contain master page
0
 
BuginatorCommented:
When your user log in, create a session:
Session["UserName"] = the username, ie from the username textbox

Make a Label in your masterpage, place it where you want to in the masterpage:
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

In the code behind file for the masterpage, MasterPage.master.cs, write the following the Page_Load event:
if (Session["UserName"] != null) Label1.Text = Session["UserName"];

Done.
0
 
informaniacCommented:
Store the id in Session and in the load event of the masterpage, set the value of the label from session
0
 
informaniacCommented:
Sorry Buginator...
0
 
BuginatorCommented:
A small correction:
if (Session["UserName"] != null) Label1.Text = Session["UserName"].ToString();

Open in new window

0
 
chandresh43Author Commented:
oh thats i don but how refresh master page
0
 
BuginatorCommented:
What do you mean? The code I gave you should be sufficient.
0
 
chandresh43Author Commented:
no men you dont get
there is radwindows where user enter user password
and that value go to mater page
so i want to refresh master page after session is created
0
 
BuginatorCommented:
Try this javascript, place it in your radwindow, within the <head> tags. It will close the radwindow and refresh the parent window (master page)

function CloseAndRefresh()
{
    window.opener.location.href = window.opener.location.href;
    window.close();
}

Also, modify your <body> tag in your radwindow to this::
< body onbeforeunload="CloseAndRefresh()">
0
 
chandresh43Author Commented:
onbeforeunload not found in asp
body tag
0
 
BuginatorCommented:
It's javascript, not ASP.NET. Here's some info about onbeforeunload. Click #1. Demo.

   <body onbeforeunload="CloseAndRefresh()">


So it would be like this, I've put some extra code for context. Only the script and body tag is important here.



<head runat="server">
    <title></title>
    <script type="text/javascript">
        function CloseAndRefresh() {
            window.opener.location.href = window.opener.location.href;
            window.close();
        }
        </script>
</head>
<body onbeforeunload="CloseAndRefresh()">

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now