How to pass username to ObjectDataSource as a parameter?

Discussion in 'ASP .Net Web Controls' started by timpera2501, Jan 19, 2006.

  1. timpera2501

    timpera2501 Guest

    I have an application where users log in with the standard .NET 2.0 login
    control and database.

    Once logged in, I want the data retrieved by an ObjectDataSource control to
    be dependent on the UserName.

    The choices I have for "Parameter Source" are:
    Cookie
    Control
    Form
    Profile
    QueryString
    Session

    I have tried putting "UserName" as the parameter name for all of these, but
    it still does not pass the variable. How do I reference the username of the
    current user and pass it to an ObjectDataSource as a parameter?

    Thanks for any help you can offer.
    -Amanda
    timpera2501, Jan 19, 2006
    #1
    1. Advertising

  2. timpera2501

    timpera2501 Guest

    I have also tried setting the "Parameter Control" to "None" and setting the
    default value to "Page.User.Identity.Name.ToString()", but that doesn't work
    either.

    No errors, but it returns an empty value to SQL server. And I have verified
    that the data is flowing correctly from SQL to the app by hardcoding a value
    into the SQL query.


    "timpera2501" wrote:

    > I have an application where users log in with the standard .NET 2.0 login
    > control and database.
    >
    > Once logged in, I want the data retrieved by an ObjectDataSource control to
    > be dependent on the UserName.
    >
    > The choices I have for "Parameter Source" are:
    > Cookie
    > Control
    > Form
    > Profile
    > QueryString
    > Session
    >
    > I have tried putting "UserName" as the parameter name for all of these, but
    > it still does not pass the variable. How do I reference the username of the
    > current user and pass it to an ObjectDataSource as a parameter?
    >
    > Thanks for any help you can offer.
    > -Amanda
    timpera2501, Jan 19, 2006
    #2
    1. Advertising

  3. timpera2501

    timpera2501 Guest

    OK.. so after further testing, it appears that "Profile.UserName",
    "Session.UserName", and "Page.User.Identity.Name" are all null.

    How can this be? I'm logged in, and the .NET 2.0 "LoginName" control is
    working on the same page.

    I'm about ready to tear my hair out. =(

    -Amanda

    "timpera2501" wrote:

    > I have also tried setting the "Parameter Control" to "None" and setting the
    > default value to "Page.User.Identity.Name.ToString()", but that doesn't work
    > either.
    >
    > No errors, but it returns an empty value to SQL server. And I have verified
    > that the data is flowing correctly from SQL to the app by hardcoding a value
    > into the SQL query.
    >
    >
    > "timpera2501" wrote:
    >
    > > I have an application where users log in with the standard .NET 2.0 login
    > > control and database.
    > >
    > > Once logged in, I want the data retrieved by an ObjectDataSource control to
    > > be dependent on the UserName.
    > >
    > > The choices I have for "Parameter Source" are:
    > > Cookie
    > > Control
    > > Form
    > > Profile
    > > QueryString
    > > Session
    > >
    > > I have tried putting "UserName" as the parameter name for all of these, but
    > > it still does not pass the variable. How do I reference the username of the
    > > current user and pass it to an ObjectDataSource as a parameter?
    > >
    > > Thanks for any help you can offer.
    > > -Amanda
    timpera2501, Jan 19, 2006
    #3
  4. timpera2501

    timpera2501 Guest

    Well, for those who care.. =).. here is what fixed it for me.

    Apparently, even tho Profile.UserName is automatically there for every
    profile, you still have to put a <profiles> section in your web.config to
    enable profiles at all.

    I had originally thought that you only added a <profiles> section to your
    web.config if you had additional fields you wanted to save info about.

    So now, it works with Profile.Username.


    "timpera2501" wrote:

    > OK.. so after further testing, it appears that "Profile.UserName",
    > "Session.UserName", and "Page.User.Identity.Name" are all null.
    >
    > How can this be? I'm logged in, and the .NET 2.0 "LoginName" control is
    > working on the same page.
    >
    > I'm about ready to tear my hair out. =(
    >
    > -Amanda
    >
    > "timpera2501" wrote:
    >
    > > I have also tried setting the "Parameter Control" to "None" and setting the
    > > default value to "Page.User.Identity.Name.ToString()", but that doesn't work
    > > either.
    > >
    > > No errors, but it returns an empty value to SQL server. And I have verified
    > > that the data is flowing correctly from SQL to the app by hardcoding a value
    > > into the SQL query.
    > >
    > >
    > > "timpera2501" wrote:
    > >
    > > > I have an application where users log in with the standard .NET 2.0 login
    > > > control and database.
    > > >
    > > > Once logged in, I want the data retrieved by an ObjectDataSource control to
    > > > be dependent on the UserName.
    > > >
    > > > The choices I have for "Parameter Source" are:
    > > > Cookie
    > > > Control
    > > > Form
    > > > Profile
    > > > QueryString
    > > > Session
    > > >
    > > > I have tried putting "UserName" as the parameter name for all of these, but
    > > > it still does not pass the variable. How do I reference the username of the
    > > > current user and pass it to an ObjectDataSource as a parameter?
    > > >
    > > > Thanks for any help you can offer.
    > > > -Amanda
    timpera2501, Jan 19, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hardy Wang
    Replies:
    1
    Views:
    2,979
    Nicholas Paldino [.NET/C# MVP]
    Dec 5, 2005
  2. Replies:
    3
    Views:
    661
  3. David Thielen

    ObjectDataSource method as another ObjectDataSource

    David Thielen, Mar 21, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    242
    Steven Cheng[MSFT]
    Mar 23, 2006
  4. Shailesh Patel
    Replies:
    0
    Views:
    450
    Shailesh Patel
    Nov 8, 2006
  5. AzamSharp
    Replies:
    2
    Views:
    176
Loading...

Share This Page