Solved

master page in asp.net

Posted on 2009-04-15
14
717 Views
Last Modified: 2012-05-07
i want when user login on page
user name will be display on master page lable


0
Comment
Question by:chandresh43
  • 5
  • 5
  • 3
  • +1
14 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 24146831
((Label)this.Master.FindControl("lblName")).Text = " Name";
0
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 24146853
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
 
LVL 5

Author Comment

by:chandresh43
ID: 24146856
this give me error
 Object reference not set to an instance of an object.
0
 
LVL 5

Author Comment

by:chandresh43
ID: 24146868
and my login page in not contain master page
0
 
LVL 5

Expert Comment

by:Buginator
ID: 24147139
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
 
LVL 20

Expert Comment

by:informaniac
ID: 24147159
Store the id in Session and in the load event of the masterpage, set the value of the label from session
0
 
LVL 20

Expert Comment

by:informaniac
ID: 24147246
Sorry Buginator...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:Buginator
ID: 24147340
A small correction:
if (Session["UserName"] != null) Label1.Text = Session["UserName"].ToString();

Open in new window

0
 
LVL 5

Author Comment

by:chandresh43
ID: 24149361
oh thats i don but how refresh master page
0
 
LVL 5

Expert Comment

by:Buginator
ID: 24149387
What do you mean? The code I gave you should be sufficient.
0
 
LVL 5

Author Comment

by:chandresh43
ID: 24149993
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
 
LVL 5

Expert Comment

by:Buginator
ID: 24150115
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
 
LVL 5

Author Comment

by:chandresh43
ID: 24154902
onbeforeunload not found in asp
body tag
0
 
LVL 5

Accepted Solution

by:
Buginator earned 500 total points
ID: 24156201
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now