Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 30th, 2008, 12:15 AM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default Membership / User question

I'm not sure if Membership works differently in 3.5 or not. I store a member's userID in a seperate table. I have a member disabled upon the createuserwizard so that an admin can validate and enable this person.

SO---in my detailsview, I am trying to have a field that will show whether a person is enabled or disabled and then click to enable or disable (still not sure the easiest way to do this)..however, my problem is in getting the value of whether the user is enabled or not.

I do capture the userID in my table and it actually populates a field in the datalist - obviously, it's a string. Is there a way to convert the userID into a parameter that will allow me to get to the user's entry in the asp_membership table?

I would sure appreciate any suggestions on how to tailor that particular field of the DataList...my thoughts were to have a button where the button's text would be dynamic - upon creation, it would evaluate whether user is enabled or disabled and then change text of button appropriately. Then on Button_click also check enabled or disabled and then run the appropriate function.

I can't even begin to do that until I figure a way to use a text representation of a UserID to find the user.

LAST question....I can get to the userID field in teh DataList by activeLabel = CType(e.Item.FindControl("ApprovedLabel"), Label) - but suppose I don't want to show the userID in the datalist--can I remove and get the value that is returned by the objectDataSource some other way - or do I have to create a hidden control and bind it and then do same as above (CType...)

Thanks, in advance,
Rob

  #2 (permalink)  
Old June 30th, 2008, 01:50 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

The User ID (the ProviderUserKey) is not a string; it's an Object.

Under the hood, the SqlServerMembershipProvider stores the ProviderUserKey as a Guid.

So, to get back the user you can do this:

Dim myId As Guid = new Guid(yourProviderUserKeyAsString)

Where yourProviderUserKeyAsString comes from depends; it could be the Query String, the SelectedValue of some control and so on.

WIth the ID you can get the user like this:

Dim myUser As MembershipUser = Membership.GetUser(myId)

You can make the ID part of the DataKeys collection of your data list control. Then it's available in the selected item.

Hope this helps,

Imar





---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
  #3 (permalink)  
Old June 30th, 2008, 08:29 AM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Imar,

It most certainly does - I was trying to look at the overloads for the getuser method and was stuck on how to convert the string to something that would retrieve.

As to the DataKeys - this is probably more a beginner topic, but I have always used code behind methods to get the value of a database return by trying to tie into the value of the control that it is bound to. What is the syntax on the control and the code behind to use DataKeys? In other words, how to I initiate it in the control - and then in what code behind function do I use and how do I reference it? How do I reference if I want more than one?

Thanks!!!
Rob

  #4 (permalink)  
Old June 30th, 2008, 10:28 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You can assign the data key like this:
Code:
<asp:DataList ID="DataList1" runat="server" DataKeyField="Id" />
And then later retrieve it like this:
Code:
DataList1.SelectedValue
Hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
  #5 (permalink)  
Old June 30th, 2008, 10:34 AM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Imar - close. Suppose, as is the case with me, the userID is not the primary key for the table (memberID is)...does that matter? Suppose I wanted to capture more than one value - let's say I want to reference userID and email?? I am only wanting to get to userID so I can run that function to get access to that user's "isactive" field in the asp_membership table...but curious how I might work this if I wanted to get access to other fields that are returned from the objectdatasource.

Thanks!
Rob

  #6 (permalink)  
Old June 30th, 2008, 11:01 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You can use the DataKeys property (which is a collection) to assign and retrieve multiple data keys...

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basedatalist.datakeys(VS .85).aspx

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
  #7 (permalink)  
Old June 30th, 2008, 04:55 PM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

Imar .. or anyone..I need help, and I have tried researching this in both my Professional ASP.NET 2.0 & 3.5 (Wrox books) and online - and I think I am getting terms mixed up.

Can you *please* explain (or point out a source that explains this) the difference between:

DataKey
DataKeyField
DataKeysArray
DataKeyName

I always took DataKeyName to be that which is the field representing the Primary key of a table - I guess I didn't realize that I could use the DataKeys to store multiple "non-primary-key" fields--and am getting really confused on the different terms above--and it's driving me crazy.

Please.

-Rob

ADDED:

Here's an example of what I am finding. In it, you can see how it is referred to as storing the "Primary Key". What confuses me is that the field I am wanting to reference is not my primary key - so, how can I set my primary key to "MemberID" and yet have reference to another key called "UserID"?

The DataGrid control contains a DataKeyField property. This optional property can be used to specify the primary key field for the data being displayed in the DataGrid. If this property is set, a separate DataGrid property, DataKeys (a collection), is populated with the primary key values for each row in the DataGrid. Hence, we can access this collection programmatically in our DeleteCommand event handler. To get the proper item out of the DataKeys collection, we simply reference the index that is equal to the clicked DataGrid row's ItemIndex. This concept is illustrated below:

LAST ADD: After some more research, please tell me if I have this correct. If you want to use DataKeys at all, you set the DataKeyField to a value which will be the primary key(s). Once you set that then a DataKey collection is created (here is my guess) that contains *all* the fields in the datasource - you the user, simply have to choose the correct one? I guess what my hangup was/is is that The "DataKeyField" is set to something - how do you refer to a different field in the DataKey collection--AND--is only those fields you put in the DataKeyField in the DataKEy collection?
  #8 (permalink)  
Old July 1st, 2008, 07:01 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Check out the MSDN documentation:

http://msdn.microsoft.com/en-us/libr...roperties.aspx

It's all in there....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
  #9 (permalink)  
Old July 1st, 2008, 08:25 AM
Friend of Wrox
 
Join Date: Jul 2006
Location: olathe, ks, USA.
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default

I am really not trying to appear negative...but I have tried everything you are telling me to. Right now, I just feel very stupid. The link you provided, and the one prior (with MSDN) only shows "one" value in the DataKeyField example. They do not show multiple DataKeys being used in any of their examples. This is literally driving me buggy. *everything* I read says that the DataKeyField is for the primary key - but I keep seeing that "DataKey"s can store more than one value--with no example. What I don't understand is...

a) How do you set, and then reference in code behind, multiple Data Keys?
b) If you use multiple DataKeys - then how does the control know which one is the "primary key" in case you want to do updates/deletes, etc.

Really, I'm trying to simply be able to reference things like UserID, in addition to the primary key, memberID - without breaking the control's understanding that memberID is the primary key.


  #10 (permalink)  
Old July 1st, 2008, 10:27 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Negative?

Anyway, I think you abusing the keys. The idea to use multiple keys is for a multi column key. There are a couple of solutions:

1. As I hinted earlier, simply store the UserId in a hidden column (on a Label for example) and retrieve it later.

2. Get the *key* Id from the database, make a call to the database to convert your own ID into the Membership ID and work from there.

3. Don't use your own ID, but make the Membership UserId the primary key of your table.

4. Just specify multiple keys; that shouldn't be a problem as .NET will do something like

Jadajadajadajada where Id = @id AND UserId = @userId

which should still result in the right record.

Personally, I prefer option 3, as it's the most natural thing to do: give your own table a proper key.....

And did you try Google:

http://www.google.com/search?hl=en&s...%22DataKeys%22

results in:

http://msconline.maconstate.edu/tuto...pnet11-06.aspx
http://www.experts-exchange.com/Prog..._23473159.html
http://www.pcreview.co.uk/forums/thread-1291942.php


Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Membership provider question aspcoder BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 July 27th, 2008 09:59 AM
Dim user As MembershipUser = Membership.GetUser(us sstuber BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 May 8th, 2008 03:42 PM
Membership User kulkarnimonica ASP.NET 2.0 Professional 2 July 12th, 2007 04:55 PM
problem with creating membership user hertendreef ASP.NET 2.0 Basics 1 April 9th, 2007 02:37 PM
Migrate user data to new membership model relaytest49 ASP.NET 2.0 Professional 2 May 24th, 2006 09:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.