ObjectDataSource Requires Current User ID

J

Jonathan Wood

I have a page with a GridView, which uses an ObjectDataSource control to
obtain the data.

The ObjectDataSource control calls a static method on a class I've created.
However, this method needs an argument that is the user key of the current
user.

I know how to use GetUser() to get a MembershipUser object and use the
ProviderUserKey property. But how can I get the ObjectDataSource to use
this?

Is there an even that would allow me to set this somehow?

Thanks!
 
M

maciek kanski

Jonathan said:
The ObjectDataSource control calls a static method on a class I've
created. However, this method needs an argument that is the user key of
the current user.
wrap existing method with the new one:

public static void YourClass.SelectMethodForObjectDataSource() {
YourClass.ExistingMethod(HttpContext.Current.User.Identity.Name);
}

and give the YourClass.SelectMethodForObjectDataSource to ObjectDataSource
 
J

Jonathan Wood

I guess I didn't think of taking that approach. I was going for a more
generic one that would work with any ID passed. But I could always
overloaded a version that gets the ID from the current user. Thanks.
 
J

Jonathan Wood

Actually, HttpContext.Current.User.Identity.Name won't work because I need
the Membership provider user key.

I can still use GetUser() and get it from there, but I wonder now if that is
the most efficient way of doing that.
 
J

Jonathan Wood

That's a large page so I could've missed it, but I'm not seeing anything
there where I could use Membership.GetUser().ProviderUserKey as the
argument. Did I miss it?

I think what is needed is an event where I can provide the value, but I
couldn't see an appropriate one.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top