.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Problem in displaying username after logged in

Posted By:      Posted Date: September 21, 2010    Points: 0   Category :ASP.Net

I having problem in display the username after a user logged in. Can anyone give some suggestions. Also, few lines of code will be appreciated.

This is my master page which has label which named Label1 on top right, i want to display the username on there after logged in. 


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class MasterPage : System.Web.UI.MasterPage
    protected void Page_Load(object sender, EventArgs e)
        Label1.Text = Session["Username"].ToString();
    protected void lbtnLogout_Click(object sender, EventArgs e)


It will display Object reference not set to an instance of an object when build the website.

Here is the Login Page

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using Syste

View Complete Post

More Related Resource Links

Problem when displaying a popup window

Hi all,
I am working on a project in which when I clicked a hyperlink a pop up window has to be displayed for 2 pages.
But at first when i did this in javascript it worked, later after i finished the whole coding suddenly an error box displayed that there is an error in webpage and want to debug

Problem displaying a page using window.showModalDialog when resizing it.

 Hi, I have a page that is displayed using window.showModalDialog, when the page is resized the tables, text boxes and everything else that is in the page with the width 100% doesn't resize (fit the page) unless a post back is used.How can I make the page keep everything in proportion when it is resized without the need to post back? 

Problem with displaying printDialog on Windows 7 64 bit

Hello.   I'm having problems with displaying PrintDialog on Windows 7 64 bit. I checked other threads on this forum and unfortunately none of the solutions worked for me.   Here are some experiences: 1. UseExDialog option does not work for me. If set to false the PrintDialog does not show at all. If set to true PrintDialog.ShowDialog() method throws SEHException. Below You can find exception stack trace: StackTrace "   in System.Windows.Forms.UnsafeNativeMethods.PrintDlgEx(PRINTDLGEX lppdex)\r\n   in System.Windows.Forms.PrintDialog.ShowPrintDialog(IntPtr hwndOwner, PRINTDLGEX data)\r\n   in System.Windows.Forms.PrintDialog.RunDialog(IntPtr hwndOwner)\r\n   in System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)\r\n   in printerDialogTest.Program.Main(String[] args) w C:\\Users\\plcmiodu\\Documents\\Visual Studio 2008\\Projects\\printerDialogTest\\printerDialogTest\\Program.cs:line 19" string 2. Setting Platform target in Build to x64 does not work either. Behaviour is exactly the same as above. 3. Setting dialog owner to this (ShowDialog(this)) does not work either. Behaviour exactly the same. The code I used for testing is as simple as possible: using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing.Printing; namespace printerDialogTest {  &

Problem displaying Date from Sql table on Calendar Control

Hi, I am displaying Event dates from SQL table on Calendar Control in ASP.NET. Also, I have GridView Control which shows event details when certain date is clicked on calendar control. But I have a problem as not all dates are displaying properly. Strangly enough only dates which have same month and day date are displayed. For example: It shows ok dates such as 08/08/2010, 09/09/2010, 10/10/2010 etc. If I click on the date which in SQL table exists as 11/25/2010 or 12/15/2010 etc (no matching month/day numbers) it shows error message saying: "System.Data.SqlClient.SqlException: Conversion failed when converting date and/or time from character string."  Follwoing is my code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.Sql; using System.Runtime.Remoting.Messaging; using System.Configuration; using System.Data.SqlClient; using System.Data; using System.Drawing; public partial class Test_Calendar : System.Web.UI.Page { SqlConnection mycn; SqlDataAdapter myda; DataSet ds = new DataSet(); DataSet dsSelDate; String strConn; private void Page_Load(object sender, System.EventArgs e) { strConn = "Data Source=mydatasource;Initial Catalog=DBname;Persist Security I

Problem with displaying ASP.NET Tabpanel in IE 8

Hi out there!I need your help concerning the following issue: In past, i used ie6 for displaying my webapplication. Since i got to ie8 width of Tabpanel and position of right border changed. It doesnt matter, how the content looks like, the right border has a fix position and the content has to be scrolled in... Maybe there is someone who had experince with that kind of issue?Kind regards,eldorado2705

Get system logged In Domain & username

Hi, I got a website with FBA authenication. I  want to get the client machine's domain & username. After lot of goggling I got the thing that if Enable annonymous is Check then it is not possible to get these things and would return "" whatever you try like HttpContext.Current.User.Identity.Name Request.LogonUserIdentity.Name Environment.UserDomainName.   Does anyone knows how to get the client's system domain & username.    

problem with displaying items in list view web part

I have a list view webpart at default display form. Default Display form display items (for example) from the contracts documents library. List view webpart also associated with the same documents library (contracts). In such case this webpart doesn't display any item. But if I add another list view web part associated with warrants document library it display item without any problems. Is it possible to bind list view webpart to another data source for contracts document library? Or maybe another solution? Thanks!

Problem with displaying and processing dynamic data


I need to dynamically generate a list of images in table format.  The images can be found in either art or picts, in temp, or in temp and in one of the other two (duplicate image). 

The idea is to display any duplicates prior to copying anything over from temp to either art or picts, so I'm thinking of adding radio buttons if the same image is found in two folders.  I also want to add a submit button.  The user selects the image they want and clicks the button.  If they want the new file it's copied over then deleted.  If they want to keep the existing file the new one is just deleted.  If they select nothing, both versions of the file are deleted.  So the table will look something like this:

temp         art            picts         process
z-123                                           delete button
() z-234                       () z-234  

Problem in display Full Name after logged in (Session Problem)


After login, i have create a session to display the Username of the logged user, however instead of display the Username, i want to display the Full_Name of the logged user

However i have no idea how it dones....Kindly if you could help me in giving suggestion / ideas. Thank you.

PersonUser Table

P_ID (PK)   =1

Username =lucy88

Password =88ycul

Full_Name = Lucy

User_Type =Admin

Login.aspx - as i do session, it will display lucy88 however i would like to display Full_Name which is Lucy.


    protected void Button1_Click(object sender, EventArgs e)
        SqlDataSource sds = new SqlDataSource();
        sds.ConnectionString = ConfigurationManager.ConnectionStrings["MyDB"].ToString();
        sds.SelectParameters.Add("Username", TypeCode.String, this.TextBox1.Text);
        sds.SelectParameters.Add("Password", TypeCode.String, this.TextBox2.Text);

        sds.SelectCommand = " SELECT * FROM [PersonUser] WHERE [Username] = @Username AND [Password] = @Password";
        DataView dv = (DataView)sds.Select(DataSourceSelectArguments.Empty);

        if (dv.Count

Problem with IE 6 in displaying colours inside a Combobox


I have a dropdownlist which has to display the list of colours. It works fine in IE 7 and IE 8 but in IE 6 I am not able to see the Colours or the dropdownlist when I scroll the toolbar down as i have long list of colours. Is it happening because something is hiding the coloured dropdownlist?

DropDownList lstSeriesColours = new DropDownList();

lstSeriesColours.ID = string.Format("lstSeriesColours_{0}", rowID);Unit.Pixel(80);"Name";"Value";

lstSeriesColours.DataTextField = "Name";

lstSeriesColours.DataValueField = "Value";


Problem displaying a view correctly in MVC app using HTML.TextBoxFor() with VB



I have a test app with a form view.

I cannot get the view to display correctly instead of displaying a series to text boxes it displays quoted html.

I suspect that my problem is related to my VB syntax for my Linq

The C# equivilant works but my shop uses VB so I must convert the code.

Here is the code from the view:

      <% Using (Html.BeginForm)%>
          <p>Your name: <%: Html.TextBoxFor(Function(m) m.Name).ToString%></p>
          <p>Your email: <%: Html.TextBoxFor(Function(m) m.Email).ToString%></p>
          <p>Your phone: <%: Html.TextBoxFor(Function(m) m.Phone).ToString%></p>
          <p>Will you attend? <br />
          <%  Dim slist As New Generic.List(Of SelectListItem)
          slist.Add(New SelectListItem With {.Text = "Yes", .Value = Boolean.TrueString})
          slist.Add(New SelectListItem With {.Text = "No", .Value = Boolean.FalseString})
       <%: Html.DropDownListFor(Function(m) m.WillAttend, slist, "Choose an option")%>
       <input type="submit" value="Submit RSVP" />
       <% End Using%>

Get Username for logged in user

I am having trouble getting a logged in username to use on an intranet site. If I use User.Identity.Name.ToString I get a blank.

 If I use Environment.UserName.ToString  I get "Network Service".

If I run the application in debug locally I get the Domain\username but not when I run it on our intranet.




Small problem with displaying custom calendar cell text from db in Safari


using VS2010

I'm using the calendar control to create a simple event calendar. I want to add a small bit of custom text just below the date of any cell that contains an event on that date.

The code:

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
      string connString = ConfigurationManager.ConnectionStrings["CalendarConnectionString1"].ToString();
      SqlConnection myConnection = new SqlConnection(connString);
      SqlDataAdapter myAdapter = new SqlDataAdapter("GetEvents", myConnection);
      DataSet myDataSet = new DataSet();
      myAdapter.Fill(myDataSet, "Table");
      //If the month is CurrentMonth
      if (!e.Day.IsOtherMonth)
        foreach (DataRow dr in myDataSet.Tables[0].Rows)
          if ((dr["Date"].ToString() != DBNull.Value.ToString()))
            DateTime dtEvent = (DateTime)dr["Date"];
            if (dtEvent.Equals(e.Day.Date))
              e.Cell.BackColor = Color.MediumAquamarine;
              Label label = new Label();
              label.Text = "</br>";
              label.Text += dr["Title"].ToString();              

Problem Displaying Data Driven Menu


I am trying to display the menu items and submenus in a navigation menu control.

I am trying the code from this page; http://www.aspnettutorials.com/tutorials/controls/sqldb-driven-menu-csharp.aspx

This is what I got so far;

 protected void Page_Load(object sender,EventArgs e) {


        DataSet GetMenuData() {
        SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
       SqlDataAdapter dadCats=new SqlDataAdapter("SELECT * FROM MenuItems",con);
        SqlDataAdapter dadProducts=new SqlDataAdapter("SELECT * FROM SubMenus",con);
        DataSet dst=new DataSet();
        return dst;


        public void PopulateMenu() {
        DataSet dst=GetMenuData();
        foreach(DataRow masterRow in dst.Tables["MenuItems"].Rows) {
        MenuItem masterItem=new MenuItem((strin

Problem in displaying values for foreign keys in Dynamic data asp.net web app


I have the following tables in my database which are as given under:


Table 2: CREATE TABLE [dbo].[PromotionCodes]( [PromotionCode] nchar NOT NULL, [CustomerPromotionDiscountID] [int] NOT NULL, [EmployeePromotionDiscountID] [int] NOT NULL, [IsActive] [bit] NOT NULL, CONSTRAINT [PK_PromotionCodes_1] PRIMARY KEY CLUSTERED ( [PromotionCode] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]

There is a foreign key relationship between columns (1) PromotionID of table PromotionDiscountValues and CustomerPromotionDiscountID of table PromotionCodes and (2) PromotionID of table PromotionDiscountValues and EmployeePromotionDiscountID of table PromotionCodes

When i browse the PromotionCodes table in the dynamic data listing, the following columns get displayed:

  1. PromotionCode

  2. IsActive

  3. Prom

Logged in Username in Sharepoint 2010 Forms Based Authentication



When using forms based authentication in Sharepoint 2010, suppose user is logged in with username "admin" and our custom membership provider name is "FBAProvider"... After logging in with this account, logged in user name is displayed like "i:0#.|FBAProvider|admin". How can make it display as it should be like just "admin"?

Thanks in advance,


problem with displaying all records in SQL 2008


Hi Guys,

I used to excute the below SQL Statement with SQL 2000 and when i removed the 2000 and Installed the SQL 2008 not all the data appeared in the report, Is there anything else should I do?

The SQL Statement is :

      If conn.State = ConnectionState.Closed Then

 conn.ConnectionString = "Provider=SQLOLEDB;server=" & Srvrname & ";database=Att;user id=sa;pwd="
      End If
    Catch ex As OleDb.OleDbException
      MsgBox("Server is not Responding", MsgBoxStyle.Critical, "ATS")

    End Try

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend