none
Using login controls to search a data source RRS feed

  • Question

  • I have a detailsview control on my form and I'm trying to configure the datasource to use the value from a loginName control, also on the same form.  When I go into the setup of my datasource, the loginName control is not available as a valid control to use.  Is it not possible to use the value of a loginName control?  Can anybody suggest another way to use the logged in user as a criteria for the datasource select statement?  I'm using EW4 connecting to an SQL2008 express database.

    Thanks

    Monday, June 6, 2011 11:08 AM

Answers

  • A user login is not something you get as an attribute of the loginname control.  You get it by asking for User.Identity.Name

    You could do this in code behind (on the appropriate event), checking to make sure there is an authenticated user, then setting a hidden label to the user name, and using that control for your database query.

    C#

    if (User.Identity.IsAuthenticated)
        Label1.Text = User.Identity.Name;
    else
        Label1.Text = "No user identity available.";

    For more details on asp.net membership, the asp.net forum would be the place to try.

    • Marked as answer by Mart77 Monday, June 6, 2011 7:18 PM
    Monday, June 6, 2011 7:06 PM

All replies

  • A user login is not something you get as an attribute of the loginname control.  You get it by asking for User.Identity.Name

    You could do this in code behind (on the appropriate event), checking to make sure there is an authenticated user, then setting a hidden label to the user name, and using that control for your database query.

    C#

    if (User.Identity.IsAuthenticated)
        Label1.Text = User.Identity.Name;
    else
        Label1.Text = "No user identity available.";

    For more details on asp.net membership, the asp.net forum would be the place to try.

    • Marked as answer by Mart77 Monday, June 6, 2011 7:18 PM
    Monday, June 6, 2011 7:06 PM
  • Thanks very much Cathy
    Monday, June 6, 2011 7:18 PM

  • This tutorial shows how to use the UserID to bring up a users data:

    http://www.homepagedoctor.com/Tutorials/ShowLoggedOnUserData.aspx



    ClarkNK, A.K.A. HomePage Doctor
    HomePageDoctor.com -- Expression Web database tutorials
    Ownertrades.com -- Created with FP, Access, Bots and Wizards
    LawOfAllTheLand.org -- Created with Expression, VWDExress, SQL Express, and ASP.NET.
    Arvixe -- My favored web host
    Tuesday, June 7, 2011 2:05 AM