Home/ASP.NET Forums/Starter Kits and Source Projects/Time Tracker Starter Kit/Display user name in the header when logged in

Display user name in the header when logged in [Answered]RSS

90 replies

Last post Mar 28, 2011 11:01 AM by agiles

Larry Dechent
  • ldechent

    ldechent

    Contributor

    6326 Points

    1577 Posts

    Re: 4 page example (8 pages if you count aspx and aspx.cs as two pages)

    Jan 06, 2009 12:47 AM|ldechent|LINK

    Admittedly, it's going to be tedious to build the four pages above to prove the example.  I estimate about 5 minutes of work to build the example.  However, after the example is created you will have a model system to which you can make alterations to see what happens as a result of the changes.

    It doesn't matter whether you use div or span or textbox so I thought, why not put in all three and prove it.

    Next, we needed several pages.  You said masterpage so I wanted this example to show that if you build the feature on the masterpage you'll never have to write anything about it on any other page.  I could have just said that, and it probably would have made sense, but it will be more real when you see it.

    We built the Default.aspx page next because if you didn't have it at some point the program would look for it and if it wasn't there you would get a white screen, and that causes panic.

    We then built the Login.aspx page (which also has a register tool) so that you can login and see how the line at the top changes.  The Login.aspx page also has a tool for logout.  This is helpful because you can login and logout and verify that the upper line is mirroring the changes without fail.

    I mentioned on the masterpage what I did with the Web Site Administration Tool (look for the hammer and world icon under Solution explorer--it's the icon furthest to the right--at least this is true for Visual Web Developer.  This note was also built there to fill space in the part that is the bottomline div on the masterpage.

    Note that we built three different div areas with three different colors.    This takes us back to the original question "where should I put it?  or in this case, where should I put them?"

    Once you are satisfied that the example works (with "them" in the blue area) move "them" to another place on the masterpage and then test the different pages again.  I think after you have moved it to three different places you will be convinced that it doesn't matter--and I think as an indirect benefit you will have a higher confidence for what you can do with a masterpage which will benefit you when you work with future designs.

    Given the amount of time that I put into building this, and the amount of time that you put into making it, I would recommend that you tell me after you have finished this, and maybe we use this example to do a few more things (it is important to mark the post as resolved and issue points both to show good faith and also because other persons seeing a "Not Resolved" and coming here and finding it resolved (after reading for five minutes) will feel something bad and I don't want any of them to be unhappy about wasting the five minutes.

    for my notes- this project is "TestLogin"

    Larry Dechent
  • qarjami

    qarjami

    Member

    228 Points

    218 Posts

    Re: 4 page example (8 pages if you count aspx and aspx.cs as two pages)

    Jan 06, 2009 07:19 PM|qarjami|LINK

    wow. great answers in detail. I will try your sample tonight and give you the feedback. and will mark this post completed.

    Thanks a lotttttt.

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Jan 07, 2009 02:30 AM|chetan.sarode|LINK

    You can use this code

    MembershipUser membershipUser = Membership.GetUser();
    if (membershipUser != null)
    {
        string loggedinuser = Membership.GetUser().ToString();
        yourdiv.InnerHtml = loggedinuser;
    }

    also there is another option to get user name

    HttpContext.Current.User.Identity

    http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • qarjami

    qarjami

    Member

    228 Points

    218 Posts

    Re: Display user name in the header when logged in

    Jan 07, 2009 03:33 AM|qarjami|LINK

    Great job guys. It worked like charm. I am going to elaborate which order they need to take place.

    step1: Add a Label right above <div login> area in masterpage.master page. Lets call that lblShowUser
    step2: on load for masterpage.master.cs page put this code

         MembershipUser
    membershipUser = Membership.GetUser();
                if (membershipUser != null)
                   {
                     
    string loggedinuser = Membership.GetUser().ToString();
                      lblShowUser.Text =
    "Welcome " + loggedinuser;
                   }
                  
    else
                  
    {
                      lblShowUser.Text =
    "";
                   }

     

  • ldechent

    ldechent

    Contributor

    6326 Points

    1577 Posts

    Re: Display user name in the header when logged in

    Jan 07, 2009 01:24 PM|ldechent|LINK

    OK, I'm going to go ahead and build a "second generation example."   What we did here was an experiment and it appears the "gamble" paid off, so I'd like to roll the dice again.  Would you like me to also include the code mentioned by the second poster, Chetan?  The reason I bring it up, I'm planning to anyway, simply so we have the value of the experience of trying something new and exploring it--but also, if you used it and you found something you liked better about it then we could use that specifically.

    I don't want to promise it but I'm thinking the next generation could have a folder called Admin which has stuff that is accessible only if a logged in person happens to have been approved as an Admin role person.  Maybe also have a customer Role too.  Please note (if you haven't come across this already)--when a person registers they immediately have a status change--but maybe that person who registered is your business competitor so you want to create a role for Customers so that you have to approve them before they actually are granted access (in this case to a folder called Customers).

    I haven't done it for a while but my memory says we can do something in the web.config file to specify folder access and then maybe once a day you go into the page (can't remember the name but it is the hammer and world icon furthest to the right under Solution Explorer) and you look at people who are registered and you give them approvals there (I'm pretty sure this can also be done programmatically.)  Are you working on a "local machine" like a laptop or a desktop, or are you working on server (like a server at work or a commercial web site provider)?

    OK, this new example might have even more files to copy but, hey, we're ready to gamble that it will be worth it, right? (and the gamble is that another person coming here for the original question is going to want to go down this same path).

    Also, when you reply post, keep telling me what you would like.  It helps to have several things because I'll start with what I know right away and then I'll work on what I need to learn while doing the rest (I'll also have a long page that has all the files and I'll update it periodically until all are finished).

    -Larry

    Larry Dechent
  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Jan 16, 2009 02:28 AM|chetan.sarode|LINK

    Nice one

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • richsoryu

    richsoryu

    Member

    12 Points

    1 Post

    Re: Display user name in the header when logged in

    Feb 22, 2009 06:59 AM|richsoryu|LINK

    Bulding off this code, I put this code in my master page:

      

    <div id="userLoggedIn" runat="server">
    </div>

     

    Then in my Page_Load method, I put this code: 

    // if user is logged in, set the innerhtml of the userLoggedIn div to show the user name
            // else, set the text telling the user how to log in.
            if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                string userName = "<p>Hello, " + System.Web.HttpContext.Current.User.Identity.Name +
                    "! Not you? <a href=\"Default.aspx\">Click here to log in.</a><p>";
                userLoggedIn.InnerHtml = userName;
            }
            else
            { 
                string userName = "<p><a href=\"week2.aspx\">Click here to log in.</a><p>";
                userLoggedIn.InnerHtml = userName; 
            }
    

     

    Now the user name displays when the user is logged in.

    Thank you for answering this guy's questions. :)

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Feb 24, 2009 02:22 AM|chetan.sarode|LINK

    Thats nice

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Aug 25, 2009 09:10 PM|Cadeey|LINK

     Hello-

    I saw this post which is pretty much what I am looking for except that I'm not using the Membership.  I am validating users against oracle table.  Is there a way to display username as they login to the page when connecting to oracle table???

     

     

  • qarjami

    qarjami

    Member

    228 Points

    218 Posts

    Re: Display user name in the header when logged in

    Aug 25, 2009 11:32 PM|qarjami|LINK

     quickest way to do it use session state to store name. (of course, u should b using stored procedure to do this).

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Aug 26, 2009 03:24 AM|chetan.sarode|LINK

     Afetr authenticating the user, store that user name in Session. Add label t Master Page then set the text to it

    Label.Text = Session["UserName"].ToString();

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Aug 26, 2009 03:42 PM|Cadeey|LINK

    How can I store the username in Session?  I know you add the Label.Text = Session["UserName"].ToString(); in the default page.  Can you tell me step by step in storing username? I am using Oracle database.

    Somehow I get his error: Object reference not set to an instance of an object

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Aug 27, 2009 02:57 AM|chetan.sarode|LINK

     How you are passing the username and password to the oracle table.

    Read it from textbox when you click the button from lagin form, if the authentication successful, store that user name in session

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Aug 27, 2009 07:54 PM|Cadeey|LINK

     Basically this is how I am passing the username and password to oracle table.

    void LoginUser(object s, EventArgs e)
        {
            bool blnAuthenticate = Authenticate(username.Text, password.Text);
            if (blnAuthenticate)
            {
                FormsAuthentication.RedirectFromLoginPage(username.Text, true);
            }
            else
            {
                lblError.Text = "Your login was invalid. Please try again.";
            }
        }
       
        bool Authenticate(string strusername, string strPassword)
        {   //declaring objects
            OracleConnection objConn = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
            OracleCommand objComd;
            OracleDataReader objDR;
            bool userFound;
           
            objComd = new OracleCommand("SELECT * FROM REGISTER " + "WHERE USER_NAME='"
                + strusername + "' AND PASSWORD='" + strPassword + "'", objConn);
           
            objConn.Open();
            objDR = objComd.ExecuteReader();
            userFound = objDR.Read();
            objDR.Close();
           
            return userFound;
        }

    From here what do I need to add in order to display username when they logged in (example: "Welcome Cadeey")

    I appreciate your help.....Smile.

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Aug 31, 2009 02:52 AM|chetan.sarode|LINK

    When the code executes

    FormsAuthentication.RedirectFromLoginPage(username.Text, true);

    store "username.Text" in Session

    Session["UserName"] = username.Text;

    When it redirects (logged in) palce this value to lable

    userNameLabel.text = "Welcome " + Session["UserName"].ToString();


     

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Aug 31, 2009 01:19 PM|Cadeey|LINK

    Thanks Chetan.  That works.

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Sep 01, 2009 02:54 AM|chetan.sarode|LINK

     Glad it helps you

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 01, 2009 01:36 PM|Cadeey|LINK

    Question about username being in case insensitive.

    I have a database table where registered users' information is stored in.  When the user registers their username is stored in as in uppercase in the database and when the user tries to login they can only use uppercase username.  I want to make the username in case insensitive.  Any help will do.

  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 01, 2009 02:36 PM|Cadeey|LINK

    Another quick question, when the user logins in my username is case sensitive (uppercase).  How can I make the username in case insensitive?  The database is storing username in uppercase letters.

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Sep 02, 2009 03:01 AM|chetan.sarode|LINK

     Why you are stroing it in UpperCase, is there any reason.

    You can pass username to databse in uppercase, while authenticating, pass in uppercase only

    bool Authenticate(string username, strin password)

    {

       string uname = username.ToUpper();

    }

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 02, 2009 03:06 PM|Cadeey|LINK

    Actually it is not storing uppercase only.  It all depends on how the user enters it when they are registering.  However, regardless of their cases (Upper or Lower) I would like to make the username case insensitive.

    For example: If user types in Cadeey or CADEEY it shouldn't matter when they are login in.

    Here's my code behind for the login page:

    void LoginUser(object s, EventArgs e)
        {
            bool blnAuthenticate = Authenticate(username.Text, password.Text);
            if (blnAuthenticate)
            {
                FormsAuthentication.RedirectFromLoginPage(username.Text, true);
                Session["UserName"] = username.Text;
            }
            else
            {
                lblError.Text = "Your login was invalid. Please try again.";
            }
        }
       
        bool Authenticate(string strusername, string strPassword)
        {   //declaring objects
            OracleConnection objConn = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
            OracleCommand objComd;
            OracleDataReader objDR;
            bool userFound;
           
            objComd = new OracleCommand("SELECT * FROM REGISTER " + "WHERE USER_NAME='"
                + strusername + "' AND PASSWORD='" + strPassword + "'", objConn);
           
            objConn.Open();
            objDR = objComd.ExecuteReader();
            userFound = objDR.Read();
            objDR.Close();
           
            return userFound;
        }

  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 08, 2009 07:54 PM|Cadeey|LINK

     I did not get the solution to my last problem.  Any ideas?

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Sep 09, 2009 02:55 AM|chetan.sarode|LINK

     You are saying that "I would like to make the username case insensitive" also

    "For example: If user types in Cadeey or CADEEY it shouldn't matter when they are login in."

    Can you please confirm on that which one you want

     

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 09, 2009 02:09 PM|Cadeey|LINK

     That is exactly what I am saying.

    If user types in Cadeey or CADEEY it shouldn't matter when they are login in."

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Sep 10, 2009 02:58 AM|chetan.sarode|LINK

     While authenticating, you can always pass username in lower case. If user provide CADEEY hen you can provide to the DB as "caseey" using ToLower()

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 10, 2009 07:36 PM|Cadeey|LINK

    Can you please show me how to pass lowercase username while authenticating using the code below?  I tried putting tolower() after .text and it's not working.

    void LoginUser(object s, EventArgs e)
        {
            bool blnAuthenticate = Authenticate(username.Text, password.Text);
            if (blnAuthenticate)
            {
                FormsAuthentication.RedirectFromLoginPage(username.Text, true);
                Session["UserName"] = username.Text;
            }
            else
            {
                lblError.Text = "Your login was invalid. Please try again.";
            }
        }
       
        bool Authenticate(string strusername, string strPassword)
        {   //declaring objects
            OracleConnection objConn = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
            OracleCommand objComd;
            OracleDataReader objDR;
            bool userFound;
           
            objComd = new OracleCommand("SELECT * FROM REGISTER " + "WHERE USER_NAME='"
                + strusername + "' AND PASSWORD='" + strPassword + "'", objConn);
           
            objConn.Open();
            objDR = objComd.ExecuteReader();
            userFound = objDR.Read();
            objDR.Close();
           
            return userFound;
        }

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Sep 11, 2009 03:00 AM|chetan.sarode|LINK

     Try this

    bool blnAuthenticate = Authenticate(username.Text.Tostring().ToLower(), password.Text);

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 11, 2009 08:38 PM|Cadeey|LINK

    Your solution works however if I have username first character as Upper and the rest Lower how would I do that?

    For example: Cadeey

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Sep 14, 2009 03:15 AM|chetan.sarode|LINK

    It will also work in that case

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 17, 2009 08:22 PM|Cadeey|LINK

     hi chetan, did you receive my last message regarding the calendar display?

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Sep 18, 2009 02:44 AM|chetan.sarode|LINK

     Yes, for that requirement I will suggest take a look at

    http://www.telerik.com/products/aspnet-ajax/calendar.aspx

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Sep 22, 2009 03:29 AM|chetan.sarode|LINK

     Have you looked into the url I provided, does it matches to your requirement

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 22, 2009 09:23 PM|Cadeey|LINK

     The URL you send me give me partial of what I was looking for.  I am able to display project due dates on the calendar but I am not able to do that based on loging username. 

    I need couple of things to happen:

    1) Employee logs in then views his/her own projects

    This is my code behind for the calendar so far.

    protected void Page_Load(object sender, EventArgs e)
        {

            Label1.Text = "Welcome, " + Session["UserName"].ToString();

           if (!Page.IsPostBack)
            {
                //calls the bind method
                BindData();
            }
        }

        protected void BindData()
        {
            OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
            OracleCommand myCommand = new OracleCommand("SELECT DISTINCT a.PROJECT_DUE FROM NEW_PROJECTS a, REGISTER b WHERE b.USER_NAME = '" + Session["UserName"]+ "'", myConnection);
            myCommand.CommandType = CommandType.Text;

            myConnection.Open();
            OracleDataReader dr = myCommand.ExecuteReader();

            while(dr.Read()==true)
            {
                //assign the calendar control dates already contained in the database
                Calendar1.SelectedDates.Add((DateTime) dr.GetOracleDateTime(0));
            }
            dr.Close();
            myConnection.Close();
        }

     

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Sep 23, 2009 03:06 AM|chetan.sarode|LINK

     I am able to display project due dates on the calendar but I am not able to do that based on loging username

    can you explain ? is query retrun perfect record that you want

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 23, 2009 01:28 PM|Cadeey|LINK

    For example, if i login as Cadeey it should only give me all active projects assigned to Cadeey.  At the moment it is displaying all projects assigned to everyone when Cadeey logins in.  Also, I would like for a teacher to view all assigned employees projects.  Below are the two tables I am using to accomplish this task.

    Table 1 = NEW_ASSIGNMENT:

    PROJECT

    DUE DATE

    REQUESTER

    DESCRIPTION

    CATEGORY

    STATUS

    ASSIGNED TO

    TEST

    9/23/09

    Teacher

    TEST1

    Biology

    Active

    Cadeey

    Table 2 = REGISTRATION:

    FIRST NAME

    LAST NAME

    EMAIL

    USER_NAME

    PASSWORD

    CONFIRM_PASSWORD

    STUDENT_ID

    REPORTS_TO

    CADEEY

    CAD

    CADEEY@HOTMAIL.COM

    CADEEY

    TEST123

    Active

    12345

    DR.JOE

     

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Sep 24, 2009 03:06 AM|chetan.sarode|LINK

     I think this can be done using Role assignment, for whom to display all project (loke Project Manager) and for Employee only displaytheir project

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 24, 2009 01:26 PM|Cadeey|LINK

    I am not using ASP.net membership.  I have created my own tables in Oracle database.  Based on my code-behind where do I go from here.

    protected void Page_Load(object sender, EventArgs e)
        {

            Label1.Text = "Welcome, " + Session["UserName"].ToString();

           if (!Page.IsPostBack)
            {
                //calls the bind method
                BindData();
            }
        }

        protected void BindData()
        {
            OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
            OracleCommand myCommand = new OracleCommand("SELECT DISTINCT a.PROJECT_DUE FROM NEW_PROJECTS a, REGISTER b WHERE b.USER_NAME = '" + Session["UserName"]+ "'", myConnection);
            myCommand.CommandType = CommandType.Text;

            myConnection.Open();
            OracleDataReader dr = myCommand.ExecuteReader();

            while(dr.Read()==true)
            {
                //assign the calendar control dates already contained in the database
                Calendar1.SelectedDates.Add((DateTime) dr.GetOracleDateTime(0));
            }
            dr.Close();
            myConnection.Close();
        }

     

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Sep 25, 2009 03:10 AM|chetan.sarode|LINK

     Then how can you identify that logged in user is Project Manager or Employee. I think you can use ASP.net membership with Oracle Databse

    http://forums.asp.net/t/1032597.aspx

    http://weblogs.asp.net/rudysetyo/archive/2008/11/20/asp-net-membership-and-role-provider-using-oracle-database-part-1.aspx

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 28, 2009 03:45 PM|Cadeey|LINK

     I am using Oracle table, I am not familiar with role managers or asp.net membership.  The URLs you gave me aren't available anymore.  Please post step by step way of creating an asp.net membership, role managers while i'm using my oracle database table. 

    Thanks

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Sep 29, 2009 03:30 AM|chetan.sarode|LINK

     This URl is opened here. Well will suggest another way.

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 29, 2009 02:26 PM|Cadeey|LINK

    I don't really think I need to use role managers in my case.  What I've been trying to test was to select username from the table and compare with the session username.  How do I do that???

    For example: I register an account with a username: Cadeey, this is then stored in my table then a project is assigned to Cadeey with a due date this is also stored in another table.  Scenario - Cadeey logs in then on calendar render selects Username and compares with session name if exists it pulls the due date.  That's all I'm trying to do for now, let me test for employees then I'll test for managers.  PLEASE HELPPPPPPPP!

    My code behind:

    protected void Page_Load(object sender, EventArgs e)
        {

            Label1.Text = "Welcome, " + Session["UserName"].ToString();

           if (!Page.IsPostBack)
            {
                //calls the bind method
                BindData();
            }
        }

        protected void BindData()
        {
            OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
            OracleCommand myCommand = new OracleCommand("SELECT DISTINCT a.PROJECT_DUE FROM NEW_PROJECTS a, REGISTER b WHERE b.USER_NAME = '" + Session["UserName"]+ "'", myConnection);
            myCommand.CommandType = CommandType.Text;

            myConnection.Open();
            OracleDataReader dr = myCommand.ExecuteReader();

            while(dr.Read()==true)
            {
                //assign the calendar control dates already contained in the database
                Calendar1.SelectedDates.Add((DateTime) dr.GetOracleDateTime(0));
            }
            dr.Close();
            myConnection.Close();
        }

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Sep 30, 2009 05:18 AM|chetan.sarode|LINK

     I will think another way and post it

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Sep 30, 2009 01:23 PM|Cadeey|LINK

    Ok..........I'll wait....Smile.

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Oct 01, 2009 03:09 AM|chetan.sarode|LINK

     If you  don't really think you need to use role managers in your case,then how you would you recognize which project to show whom

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Oct 01, 2009 02:31 PM|Cadeey|LINK

    I have two tables: Registration and New_Projects

    Registration table has the following fields: ID, FIRST NAME, LAST NAME, EMAIL, REPORTS TO MANAGER, USERNAME, PASSWORD, CONFIRM PASSWORD

    New_Projects has the following fields: PROJECT NAME, DUE DATE, REQUESTED MANAGER, DESCRIPTION, CATEGORY, PROJECT STATUS, ASSIGNED TO MANAGER, PRIORITY LEVEL (LOW, MEDIUM, HIGH)

    When employees registers with username it stores in registration table. For new projects table, the employees are assigned to projects with due dates with their requested manager.

    What I tried to do:
    I tried to compare the username that's stored in registration table with the session username which are identical and if its the same then I select the project due date for all active projects.  And for managers which I haven't tried yet, I'd like to say if username is manager then select all employees reports to that manager and their project due dates (all active ones).

    protected void Page_Load(object sender, EventArgs e)
        {

            Label1.Text = "Welcome, " + Session["UserName"].ToString();

           if (!Page.IsPostBack)
            {
                //calls the bind method
                BindData();
            }
        }

        protected void BindData()
        {
            OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
            OracleCommand myCommand = new OracleCommand("SELECT DISTINCT a.PROJECT_DUE FROM NEW_PROJECTS a, REGISTER b WHERE b.USER_NAME = '" + Session["UserName"].ToString()+ "' AND a.PROJ_STATUS = 'Active'", myConnection);
            myCommand.CommandType = CommandType.Text;

            myConnection.Open();
            OracleDataReader dr = myCommand.ExecuteReader();

            while(dr.Read()==true)
            {
                //assign the calendar control dates already contained in the database
                Calendar1.SelectedDates.Add((DateTime) dr.GetOracleDateTime(0));
            }
            dr.Close();
            myConnection.Close();
        }

    This compiles without an error but not getting the result I want.

  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Oct 01, 2009 08:51 PM|Cadeey|LINK

     Hi Chedan-

    Please disregard the previous message.  I've resolved the issue.

    Thanks newayz.

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Oct 05, 2009 03:11 AM|chetan.sarode|LINK

     Thats nice

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Oct 08, 2009 03:05 AM|chetan.sarode|LINK

    Can ypu please tell how you resolved it 

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Oct 14, 2009 08:02 PM|Cadeey|LINK

    Hi Chetan-

    Basically, I've used SQL triggers to compare usernames.  It's similar to using asp.net roles.

    Now I have another question.  In my calendar, I want to do the following things:

    1) Select a due date then redirect user to edit form while it populates data from new_project form.
    2) Allow user to update fields then add an audit field which displays time, day it got updated and user who updated it.

  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Oct 15, 2009 08:29 PM|Cadeey|LINK

    Here's my code:

    public partial class _Default : System.Web.UI.Page

    {

            protected void Page_Load(object sender, EventArgs e)

        {

     

            Label1.Text = "Welcome, " + Session["UserName"].ToString();

            BindData();

        }

     

        protected void BindData()

        {

            if (!IsPostBack)

            {

                if (Session["UserName"].ToString() != null)

                {

                    string SessionName = Session["UserName"].ToString();

                    //Response.Write(Session["UserName"].ToString());

     

                    // Declare the query string.

                    OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);

                    OracleCommand myCommand = new OracleCommand("SELECT a.PROJECT_DUE FROM NEW_PROJECTS a WHERE upper(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "' or upper(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString()+ "'and a.proj_status = 'Active'", myConnection);

                    myCommand.CommandType = CommandType.Text;

     

                    myConnection.Open();

                    OracleDataReader dr = myCommand.ExecuteReader();

     

                    while (dr.Read() == true)

                    {

                        //assign the calendar control dates already contained in the database

                        Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0));

                    }

                    dr.Close();

                    myConnection.Close();

                }

            }

        }

     

       

        protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)

        {

            FormsAuthentication.SignOut();

            Response.Redirect("Login.aspx");

        }

     

     

     

    protected void Calendar1_SelectionChanged(object sender, EventArgs e)

    {

          I NEED CODE THAT WILL ALLOW ME TO SELECT THE DUE DATES AND POPULATE DATA FROM NEW_PROJECT PAGE TO EDIT PAGE

    }

     

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Oct 16, 2009 03:19 AM|chetan.sarode|LINK

     You can query to DB and compaire the project dates so that you can get due date and populate data

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Oct 16, 2009 02:51 PM|Cadeey|LINK

    I need start-up code to begin since I am learning. 

  • TATWORTH

    TATWORTH

    All-Star

    72445 Points

    14018 Posts

    MVP

    Re: Display user name in the header when logged in

    Oct 16, 2009 04:21 PM|TATWORTH|LINK

    >I need start-up code to begin since I am learning.
    What language are you using?

    Click "Mark as Answer" on the post that helped you.
    This earns you a point and marks your thread as Resolved so we will all know you have been helped.
    FAQ on the correct forum http://forums.asp.net/p/1337412/2699239.aspx#2699239
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Oct 18, 2009 03:59 PM|Cadeey|LINK

    Asp.net....C# 

  • TATWORTH

    TATWORTH

    All-Star

    72445 Points

    14018 Posts

    MVP

    Re: Display user name in the header when logged in

    Oct 18, 2009 06:30 PM|TATWORTH|LINK

    If the user is on the same local network, then use

        /// <summary>
        /// Gets logged-in user name
        /// </summary>
        /// <returns>logged-in user name</returns>
        public static string GetUserName
        {
          get { return Environment.UserName; }
        }

    Click "Mark as Answer" on the post that helped you.
    This earns you a point and marks your thread as Resolved so we will all know you have been helped.
    FAQ on the correct forum http://forums.asp.net/p/1337412/2699239.aspx#2699239
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Oct 19, 2009 02:57 PM|Cadeey|LINK

    This wont work in my case, because I am storing Username in a session state (From DB).

    Here's my code:

    public partial class _Default : System.Web.UI.Page

    {

            protected void Page_Load(object sender, EventArgs e)

        {

     

            Label1.Text = "Welcome, " + Session["UserName"].ToString();

            BindData();

        }

     

        protected void BindData()

        {

            if (!IsPostBack)

            {

                if (Session["UserName"].ToString() != null)

                {

                    string SessionName = Session["UserName"].ToString();

                    //Response.Write(Session["UserName"].ToString());

     

                    // Declare the query string.

                    OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);

                    OracleCommand myCommand = new OracleCommand("SELECT a.PROJECT_DUE FROM NEW_PROJECTS a WHERE upper(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "' or upper(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString()+ "'and a.proj_status = 'Active'", myConnection);

                    myCommand.CommandType = CommandType.Text;

     

                    myConnection.Open();

                    OracleDataReader dr = myCommand.ExecuteReader();

     

                    while (dr.Read() == true)

                    {

                        //assign the calendar control dates already contained in the database

                        Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0));

                    }

                    dr.Close();

                    myConnection.Close();

                }

            }

        }

     

       

        protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)

        {

            FormsAuthentication.SignOut();

            Response.Redirect("Login.aspx");

        }

     

     

     

    protected void Calendar1_SelectionChanged(object sender, EventArgs e)

    {

          I NEED CODE THAT WILL ALLOW ME TO SELECT THE DUE DATES AND POPULATE DATA FROM NEW_PROJECT PAGE TO EDIT PAGE

    }

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Oct 20, 2009 03:27 AM|chetan.sarode|LINK

    I guess you have already resolved the code for getting the user name 

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Oct 20, 2009 07:54 PM|Cadeey|LINK

    I did figured out getting the username, I need help with the calendar selection dates and redirecting to a new page.

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Oct 21, 2009 03:15 AM|chetan.sarode|LINK

    There is Selectionchnaged event for Calendar, you can get the selected date from it 

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Oct 21, 2009 01:37 PM|Cadeey|LINK

    Chetan-

    That's the part I need help with....The SelectionChanged Event.  I want to select only the due dates in the calendar and redirect to another page by populating data from another page.  Please see my code below and help me in this matter ASAP.

    Here's my code:

    public partial class _Default : System.Web.UI.Page

    {

            protected void Page_Load(object sender, EventArgs e)

        {

     

            Label1.Text = "Welcome, " + Session["UserName"].ToString();

            BindData();

        }

     

        protected void BindData()

        {

            if (!IsPostBack)

            {

                if (Session["UserName"].ToString() != null)

                {

                    string SessionName = Session["UserName"].ToString();

                    //Response.Write(Session["UserName"].ToString());

     

                    // Declare the query string.

                    OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);

                    OracleCommand myCommand = new OracleCommand("SELECT a.PROJECT_DUE FROM NEW_PROJECTS a WHERE upper(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "' or upper(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString()+ "'and a.proj_status = 'Active'", myConnection);

                    myCommand.CommandType = CommandType.Text;

     

                    myConnection.Open();

                    OracleDataReader dr = myCommand.ExecuteReader();

     

                    while (dr.Read() == true)

                    {

                        //assign the calendar control dates already contained in the database

                        Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0));

                    }

                    dr.Close();

                    myConnection.Close();

                }

            }

        }

     

       

        protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)

        {

            FormsAuthentication.SignOut();

            Response.Redirect("Login.aspx");

        }

     

     

     

    protected void Calendar1_SelectionChanged(object sender, EventArgs e)

    {

          I NEED CODE THAT WILL ALLOW ME TO SELECT THE DUE DATES AND POPULATE DATA FROM NEW_PROJECT PAGE TO EDIT PAGE

    }

  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Oct 22, 2009 07:12 PM|Cadeey|LINK

    Hi Chetan-

    I found some code for my SelectionChanged event:

     Protected void Calendar1_SelectionChanged(object sender, EventArgs e)

    {
    Response.Redirect("edit_project.aspx?PROJECT_DUE=" + (System.DateTime)Calendar1.SelectedDate);

    System.DateTime d = default(System.DateTime);

    //grab project due date

    d = (System.DateTime)Request["PROJECT_DUE"];
    }

    However, I am getting this error message: Cannot convert type 'string' to 'System.DateTime'

    Am I missing something???


     



     

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Oct 26, 2009 03:33 AM|chetan.sarode|LINK

    d = (System.DateTime)Request["PROJECT_DUE"].Tostring();

    http://stackoverflow.com/questions/773284/cannot-convert-type-string-to-system-datetime

    http://www.eggheadcafe.com/aspnet_answers/NETcsharp/May2006/post27411850.asp
     

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Oct 29, 2009 09:28 PM|Cadeey|LINK

    Hi Chetan-

    I've put the pieces together on selecting days from calendar.  Now I am trying to load selected date data into a form.  For some reason, when I select a date from the calendar I am getting this date displayed '01/01/0001'.  Where is this coming from and what am I doing wrong or missing based on my code behind below?  PLEASE HELP!!!
     
    Calendar Render

    protected void Calender1_DayRender(object sener, DayRenderEventArgs e)
    {
    // Declare the query string.

    OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
    OracleCommand myCommand = new OracleCommand("SELECT a.PROJECT_DUE FROM NEW_PROJECTS a WHERE upper(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "' or upper(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'and a.proj_status = 'Active'", myConnection);
    OracleDataReader dr;

    myConnection.Open();
    dr = myCommand.ExecuteReader();

    while (dr.Read())
    {
    //assign the calendar control dates already contained in the database
    Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0));
    }
    dr.Close();
    myConnection.Close();
    }
     
    Calendar Selection
     
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
    foreach (DateTime SelectedDate in Calendar1.SelectedDates)
    {
    Response.Redirect(
    "edit_project.aspx?PROJECT_DUE=" + Calendar1.SelectedDate.ToString("dd-MMM-yy"));

    System.
    DateTime d = default(System.DateTime);
    //grab project due date
    d = DateTime.Parse(Request["PROJECT_DUE"]);
    // LoadData();
    }
    }
     
    Form Load
     
    protected void LoadData()
    {
    //load data
    OracleConnection objConn = new OracleConnection();
    //string User_Name = User_Name.Substring;
    //string Password = Password.Substring;
    string strora = "SELECT PROJECT_NAME,PROJECT_DUE, REQUESTED_MANAGER, PROJ_DESCRIPTION, PROJ_CATEGORY, PROJ_STATUS, ASSIGNED_TO, PRIORITY_LEVEL FROM NEW_PROJECTS WHERE PROJECT_DUE = '" + Calendar1.SelectedDate.ToString("dd-MMM-yy") + "'";
    objConn.ConnectionString =
    ConfigurationManager.AppSettings["DSN"];
    OracleCommand objcmd = new OracleCommand(strora, objConn);
    objcmd.CommandType =
    CommandType.Text;
    objConn.Open();
    OracleDataReader reader = objcmd.ExecuteReader();
    reader.Read();
    Response.Write(Calendar1.SelectedDate.ToLongDateString());
    for (int x = 0; x < reader.FieldCount; x++)
    {
    // Response.Write("Project_Name");
    //Response.Write(Project_Name.Text);
     switch (reader.GetName(x).ToString())
    {
    case "PROJECT_NAME":
    Project_Name.Text = reader.GetValue(x).ToString();
    break;
    case "PROJECT_DUE":
    Project_Due.Text = reader.GetValue(x).ToString();
    break;
    case "REQUESTED_MANAGER":
    Requested_Manager.Text = reader.GetValue(x).ToString();
    break;
    case "PROJ_DESCRIPTION":
    Proj_Description.Text = reader.GetValue(x).ToString();
    break;
    case "PROJ_CATEGORY":
    Proj_Category.Text = reader.GetValue(x).ToString();
    break;
    case "PROJ_STATUS":
    Proj_Status.Text = reader.GetValue(x).ToString();
    break;
    case "ASSIGNED_TO":
    Assigned_To.Text = reader.GetValue(x).ToString();
    break;
    case "PRIORITY_LEVEL":
    Priority_Level.Text = reader.GetValue(x).ToString();
    break;
    }
    }

    objConn.Close();
    }

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Nov 03, 2009 02:07 AM|chetan.sarode|LINK

     I think the date '01/01/0001' is displayed is by default, mean it is not bimding the control itself just debug the code lets see whether from DB date field is populating or not

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Nov 03, 2009 02:57 PM|Cadeey|LINK

    My date is not binding with database.  Based on my code, how can I pass my due date so that it binds.  Please look through my code and let me know where I am missing. Basically, I want to be able to select a due date and load that due date's data ONLY into an edit form.

    Calendar Render Function

    protected
    void Calender1_DayRender(object source, DayRenderEventArgs e)
    {
    // Declare the query string.
    OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
    OracleCommand myCommand = new OracleCommand("SELECT to_date(a.PROJECT_DUE,'MM-dd-yyyy') FROM NEW_PROJECTS a WHERE upper(a.REPORTS_TO_UTSWID) = '" + Session["UserName"].ToString() + "'or lower(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "' or upper(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'and a.proj_status = 'Active'", myConnection);
    OracleDataReader dr;
     
    myConnection.Open();
    dr = myCommand.ExecuteReader();
     
    while (dr.Read())
    {
    //assign the calendar control dates already contained in the database
    Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0));
    }
    dr.Close();
    myConnection.Close();
    }
     
    Calendar SelectionChanged Function
     
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {

    Response.Redirect(
    "edit_project.aspx?PROJECT_DUE=" + Calendar1.SelectedDate.ToString("MM/dd/yyyy"));
    }
     
    Form Load Function
     
    protected void LoadData()
    {
    //load data
    OracleConnection objConn = new OracleConnection();
    // string User_Name = User_Name.Substring;
    //string Password = Password.Substring;
    // Response.Write(Calendar1.SelectedDate.ToString("MM/dd/yy"));
    string strora = "SELECT PROJECT_NAME, REQUESTED_MANAGER, PROJ_DESCRIPTION, PROJ_CATEGORY, PROJ_STATUS, ASSIGNED_TO, PRIORITY_LEVEL FROM NEW_PROJECTS WHERE PROJECT_DUE = 'to_char(" + Calendar1.SelectedDate.ToString("MM/DD/yyyy") + ")'";
    objConn.ConnectionString =
    ConfigurationManager.AppSettings["DSN"];
    OracleCommand objcmd = new OracleCommand(strora, objConn);
    objcmd.CommandType =
    CommandType.Text;
    objConn.Open();
    OracleDataReader reader = objcmd.ExecuteReader();
    reader.Read();
    //Response.Write(Calendar1.SelectedDate.ToString("MM/dd/yy"));
    for (int x = 0; x < reader.FieldCount; x++)
    {
    //Response.Write("Project_Name");
    // Response.Write(Project_Name.Text);
    switch (reader.GetName(x).ToString())
    {
    case "PROJECT_NAME":
    Project_Name.Text = reader.GetValue(x).ToString();
    break;
    case "PROJECT_DUE":
    Project_Due.Text = reader.GetValue(x).ToString();
    break;
    case "REQUESTED_MANAGER":
    Requested_Manager.SelectedValue = reader.GetValue(x).ToString();
    break;
    case "PROJ_DESCRIPTION":
    Proj_Description.Text = reader.GetValue(x).ToString();
    break;
    case "PROJ_CATEGORY":
    Proj_Category.SelectedValue = reader.GetValue(x).ToString();
    break;
    case "PROJ_STATUS":
    Proj_Status.SelectedValue = reader.GetValue(x).ToString();
    break;
    case "ASSIGNED_TO":
    Assigned_To.SelectedValue = reader.GetValue(x).ToString();
    break;
    case "PRIORITY_LEVEL":
    Priority_Level.SelectedValue = reader.GetValue(x).ToString();
    break;
    }
    }
     
    objConn.Close();
    }

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Nov 04, 2009 02:00 AM|chetan.sarode|LINK

    Will look into it 

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Nov 04, 2009 02:39 AM|Cadeey|LINK

    Thanks Chetan. Please try to help me as I'm soo frustrated with this calendar thing.  When can I expect to see a solution??? 

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Nov 05, 2009 02:11 AM|chetan.sarode|LINK

    Use the TodaysDate property to determine today's date. You can also use this property to programmatically set the value for today's date on the Calendar control.

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.todaysdate.aspx 

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Nov 05, 2009 07:26 PM|Cadeey|LINK

    Chetan, this is not helping me at all.

    Can you please post C# code in which I am able to select a datadriven date from calendar and once the date is selected data is populated into a form.  This sounds simple but difficult to do.  PLEASE HELP!

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Nov 06, 2009 01:57 AM|chetan.sarode|LINK

    You mean to say that following line didn't set the dat what you want, correct

    //assign the calendar control dates already contained in the database
    Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0));
     

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Nov 06, 2009 02:59 AM|Cadeey|LINK

    yes 

  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Nov 06, 2009 03:06 AM|Cadeey|LINK

    For some reason this code of line:  

    Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0)); is displaying my dates from the database, but when I select it is not giving me the right date, I am getting the minvalue set(01/01/0001).

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Nov 09, 2009 02:04 AM|chetan.sarode|LINK

    If the values are binding properly first time and while selecting it is not gettimg that means the values are not eprsisited. Can you just confirm while selecting it is not binding again may be thats hw values not persisted 

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Nov 09, 2009 09:13 PM|Cadeey|LINK

    I need to know how I can pass my calendar selected date from my default page to my redirect page.  Here's my code behind:

    Default page – Calendar   

    public partial class _Default : System.Web.UI.Page

    {

       

     

        protected void Page_Load(object sender, EventArgs e)

        {

           

     

            Label1.Text = "Welcome, " + Session["UserName"].ToString();

     

            if (!IsPostBack)

            {

                if (Session["UserName"].ToString() != null)

                {

                    string SessionName = Session["UserName"].ToString();

                  

                }

     

     

            }

     

        }

     

         

        protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)

        {

            FormsAuthentication.SignOut();

            Response.Redirect("Login.aspx");

        }

     

        protected void Calender1_DayRender(object source, DayRenderEventArgs e)

        {

           

           

            // Declare the query string.

     

            OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);

            OracleCommand myCommand = new OracleCommand("SELECT to_date(a.PROJECT_DUE,'MM/DD/YYYY') FROM NEW_PROJECTS a WHERE upper(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "' or upper(a.ASSIGNED_ID) = '" + Session["UserName"].ToString() + "'or lower(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'and a.proj_status = 'Active'", myConnection);

            OracleDataReader dr;

     

     

            myConnection.Open();

            dr = myCommand.ExecuteReader();

          

         

            while (dr.Read())

           {

               //assign the calendar control dates already contained in the database

              

            Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0));

            e.Cell.Text = "<a href='edit_project.aspx?PROJECT_DUE=" + e.Day.Date.ToString("MM/dd/yyyy") + "'>" + e.Day.DayNumberText + "</a>";

       

           }

          

           dr.Close();

           myConnection.Close();

          

       }

     

       protected void Calendar1_SelectionChanged(object sender, EventArgs e)

        {

     

            OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);

            OracleCommand myCommand = new OracleCommand("SELECT PROJECT_NAME, PROJECT_DUE, REQUESTED_MANAGER, PROJ_DESCRIPTION, PROJ_CATEGORY, PROJ_STATUS, ASSIGNED_TO, PRIORITY_LEVEL FROM NEW_PROJECTS  WHERE PROJECT_DUE = '" + Calendar1.SelectedDate.ToString("MM/dd/yyyy") + "'", myConnection);

            OracleDataReader dr;

     

     

                myConnection.Open();

                dr = myCommand.ExecuteReader();

          

         

               while (dr.Read())

                {

       

                   

                    Response.Write(dr.GetString(0));

                    Response.Write(dr.GetString(1));

                    Response.Write(dr.GetString(2));

                    Response.Write(dr.GetString(3));

                    Response.Write(dr.GetString(4));

                    Response.Write(dr.GetString(5));

                    Response.Write(dr.GetString(6));

                    Response.Write(dr.GetString(7));

                }

             

        }

     

          

    }

     

     

           

     Redirect page

    public partial class _Default : System.Web.UI.Page

    {

     

        protected void Page_Load(object sender, EventArgs e)

        {

     

          

            if (!Page.IsPostBack)

            {

               

                               

     

                LoadData();

     

            }

     

        }

     

     

           

     

        protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)

        {

            FormsAuthentication.SignOut();

            Response.Redirect("Login.aspx");

        }

     

        protected void btnShowCal_Click(object sender, EventArgs e)

        {

            Calendar1.Visible = true;

        }

        /************************************************************/

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)

        {

            Project_Due.Text = Calendar1.SelectedDate.ToString("MM/dd/yyyy");

     

            Calendar1.Visible = false;

        }

     

     

     

        protected void LoadData()

        {

         

     

            //load data

          

            OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);

            OracleCommand myCommand = new OracleCommand("SELECT PROJECT_NAME, PROJECT_DUE, REQUESTED_MANAGER, PROJ_DESCRIPTION, PROJ_CATEGORY, PROJ_STATUS, ASSIGNED_TO, PRIORITY_LEVEL FROM NEW_PROJECTS  WHERE PROJECT_DUE = '" + Calendar1.SelectedDate.ToString("MM/dd/yyyy")   + "'", myConnection);

            OracleDataReader dr;

     

     

            myConnection.Open();

            dr = myCommand.ExecuteReader();

           

           

            while (dr.Read())

            {

               

    Project_Name.Text = (string)dr["Project_Name"];

    Project_Due.Text = (string)dr["Project_Due"]; //this is the problem due date is not binding with the calendar selection date

                Requested_Manager.SelectedValue = (string)dr["Requested_Manager"];

                Proj_Description.Text = (string)dr["Proj_Description"];

                Proj_Category.SelectedValue = (string)dr["Proj_Category"];

                Proj_Status.SelectedValue = (string)dr["Proj_Status"];

                Assigned_To.SelectedValue = (string)dr["Assigned_To"];

                Priority_Level.SelectedValue =(string)dr["Priority_Level"];}

     

     

            myConnection.Close();

           

        }

     

        }

    }

        

     

            

     

              

     

          

                  

                 

       

     

          

      

     

     

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Nov 10, 2009 02:07 AM|chetan.sarode|LINK

    You have already done it

    e.Cell.Text = "<a href='edit_project.aspx?PROJECT_DUE=" + e.Day.Date.ToString("MM/dd/yyyy") + "'>" + e.Day.DayNumberText + "</a>";

    is there any  issue with above code

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Nov 10, 2009 02:15 PM|Cadeey|LINK

    When I click my highlighted calendar date, it shows the date selected but when I redirect to the next page it is not populating the correct selected calendar date.  It is populating 01/01/0001. What am I doing wrong?  This is really weird. Somehow I need to pass the selected date to my next page, how to do that??? Please look through my code and let me know what I am missing. This might be clear to me.

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Nov 11, 2009 02:11 AM|chetan.sarode|LINK

    As I alreay told you, you can pass it in query string or Store it in Session so that you can access it on another page 

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Nov 11, 2009 08:09 PM|Cadeey|LINK

    Please show me how to pass it in query string or Store it in Session from my calendarselectionchanged code.  That's the part I am confuse about. I dont' know where to begin. 

  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Nov 11, 2009 09:43 PM|Cadeey|LINK

    Hey Chetan-

    Please disregard this message. I've solved the problem..........YEEEEEY....WHEW! 

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Nov 12, 2009 02:03 AM|chetan.sarode|LINK

    Thats nice, you solved the problem. Cabn you just let me know how you solved I mean using QueryString or Session 

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Nov 12, 2009 01:23 PM|Cadeey|LINK

    I've used QueryString. 

  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Nov 12, 2009 09:10 PM|Cadeey|LINK

    I got one more question: How do I display project names that's stored in database in my calendar.

    Here's my code-behind (CalendarDayRender):

     protected void Calender1_DayRender(object source, DayRenderEventArgs e)
        {
           
           
            // Declare the query string.

            OracleConnection myConnection = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
            OracleCommand myCommand = new OracleCommand("SELECT to_date(a.PROJECT_DUE,'MM/DD/YYYY'), PROJECT_NAME FROM NEW_PROJECTS a WHERE upper(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.REPORTS_TO_ID) = '" + Session["UserName"].ToString() + "' or upper(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'or lower(a.ASSIGNED_TO_ID) = '" + Session["UserName"].ToString() + "'and a.proj_status = 'Active'", myConnection);
            OracleDataReader dr;


            myConnection.Open();
            dr = myCommand.ExecuteReader();

            while (dr.Read())
            {
              
             
                //assign the calendar control dates already contained in the database
                string d1;
                d1 = e.Day.Date.ToString("MM/dd/yyyy");
                Calendar1.SelectedDates.Add((DateTime)dr.GetOracleDateTime(0));

              

                  
                e.Cell.Text = "<a href='edit_project.aspx?PROJECT_DUE=" + d1 + "'>" + e.Day.DayNumberText + "</a>";
             
            }

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Nov 13, 2009 02:02 AM|chetan.sarode|LINK

    What do you mean by this

    How do I display project names that's stored in database in my calendar.

    Do you want to show Project name in Calendar along with dates 

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • Cadeey

    Cadeey

    Member

    102 Points

    55 Posts

    Re: Display user name in the header when logged in

    Nov 13, 2009 09:31 PM|Cadeey|LINK

    yes, that's what I mean.  I'm pulling the project name from the database. 

  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Nov 16, 2009 02:12 AM|chetan.sarode|LINK

    I am not sure if we can show the project name in calendar. May br for that you need third party control 

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • chetan.sarode

    chetan.sarod...

    All-Star

    72159 Points

    12189 Posts

    Re: Display user name in the header when logged in

    Nov 18, 2009 02:08 AM|chetan.sarode|LINK

    Any updates on this 

    Chetan Sarode
    Team Lead, Product Development
    Approva Systems Pvt Ltd, Pune, India.
  • agiles

    agiles

    Member

    2 Points

    1 Post

    Re: Display user name in the header when logged in

    Mar 28, 2011 11:01 AM|agiles|LINK

    when you validate the user, you can catch firstname in session then you can used it whatever you want it.

    in code behind file where the login validation, something like this:

             internal bool ValidateUser(string userName, string passWord)
            {
                SqlConnection conn;
                string currentName = null;
                string firstname = null;

                //// userName must not be null
                if (null == userName)
                {
                    return false;
                }

                //// passWord must not be null
                if (null == passWord)
                {
                    return false;
                }

     try
                {                       
                    //// connect to your  SQL Server.
                    conn = DB connection string;
                    string sqlUserName;
                    string sqlfirstname;
                    //// Create SqlCommand to select passwor and username fields from UserData table given supplied userName passWord.
                    sqlUserName = "SELECT UserName,Password FROM [your table name] ";
                    sqlUserName += " WHERE (UserName ='" + userName + "')";              
                    sqlUserName += " AND (Password ='" + passWord + "')";               
                    SqlCommand com = new SqlCommand(sqlUserName, conn);

                    //// Create SqlCommand to select firstname and lastname fields from UserData table.
                    sqlfirstname = "SELECT FirstName,LastName FROM [your table name] ";
                    sqlfirstname += " WHERE (UserName ='" + userName + "')";             
                    SqlCommand command2 = new SqlCommand(sqlfirstname, conn);
                        
                    currentName = (string)com.ExecuteScalar();
                    firstname = (string)command2.ExecuteScalar();
                    //// Cleanup command and connection objects.
                    conn.Dispose();
                    conn.Close();
                }
                catch (Exception ex)
                {
                    // Add error handling here for debugging.
                    // This error message should not be sent back to the caller.
                    System.Diagnostics.Trace.WriteLine("[ValidateUser] Exception " + ex.Message);
                }

                if (currentName != null)
                {
                    Session["UserAuthentication"] = userName;
                    Session["firstname"] = firstname;
                    ////  Session.Timeout is set in web.config file.
                    return true;
                }
                else
                {
                    Session["UserAuthentication"] = string.Empty;
                    return false;
                }
            }

    then add this line of code to .aspx file you want to display the firstname. for example master.aspx

               <div class="link" id="divid" style="float: right">
                                <asp:LoginName id="LoginName1" runat="server" />                      
                                </div>

     

    and then add this line of code in the .cs file ex:(master.cs) under page_load.

    protected void Page_Load(object sender, EventArgs e)
            {
                ////this can come from anywhere like session, database
                string firstname = (string)(Session["firstname"]);
                LoginName1.FormatString = "Sign in as" + " - " + firstname; ////output: Sign in as - username
            }

    IS this helpful for you???????

  • ‹ Previous Thread|Next Thread ›