 |
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
 | This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 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
|
|
|
|
|

May 3rd, 2007, 01:08 PM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Wrox Blog
Hello,
I have created user accounts for my users so I wanted to know how I could get the blog entry elements (after login) ex. edit this entry hyperlink. Unique to my user. SO that when in edit mode they are editing their out stuff and adding their own stuff.
Sincerely,
Computergirl
|
|

May 3rd, 2007, 02:57 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
A MembershipUser exposes a ProviderUserKey which is a Guid by default. When a user creates a Blog entry, you can get the ProviderUserKey from Membership.GetUser and store it in your BlogEntry.
Then when you display items you can show or hide the edit link depending on whether the the current item belongs to the current user.
Does this help?
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

May 3rd, 2007, 09:36 PM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I get that but in which . vb to I put it under the BLog Entries, or Blog Entriese Filter. Exactly What do I write?
|
|

May 4th, 2007, 01:03 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I think I would modify the BlogEntries control as that's the one that displays the actual entries. The Filter is only used to,..... filter ;)
Inside BlogEntries, you can handle the ItemCommand event of the DataList, use e.Item.FindControl to find your Edit link and then hide or display it depending on the user's rights.
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

May 7th, 2007, 02:49 PM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello Imar,
This is what I wrote is it correct? If not, what is?
Protected Sub dlBlogEntries_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs ) Handles dlBlogEntries.ItemCommand
If e.Item.FindControl("EditingId") Then ' Then
Membership.GetUser().ProviderUserKey.ToString()
End If
End Sub
Sincerely,
Computergirl
|
|

May 7th, 2007, 03:41 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
If it works, than it's correct, isn't it? ;)
But no, I don't think this is correct.
Few things:
1. e.Item.FindControl("EditingId") returns a Control, not a Boolean indicating whether it can be found or not. So, you'll need to do something else with it to make this code more useful.
2. Membership.GetUser().ProviderUserKey.ToString() isn't doing anything. You grab the User, get its ID, convert the Guid to a string and that's it. You're not really using it anywhere.
3. You're not really hiding the Edit link.
I think I put you on the wrong track by saying you need to ItemCommand. It's ItemDataBound that you want. The following (untested) code should probably work:
Code:
Protected Sub dlBlogEntries_ItemDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) _
Handles dlBlogEntries.ItemDataBound
Dim myDataRowView As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim userId As Guid = CType(Membership.GetUser().ProviderUserKey, Guid)
Dim posterId As Guid = CType(myDataRowView("PostedBy"), Guid)
Dim lnkEdit As LinkButton = CType(e.Item.FindControl("lnkEdit"), LinkButton)
If userId.Equals(userId) Then
lnkEdit.Visible = False
End If
End Sub
You also need to remove the Visible='<%#CanEdit()%>' from the lnkEdit control.
This code also assumes you have a column called PostedBy which holds the Guid of the user that posted the Blog entry.
I haven't tested or run this code, so you may need to tweak it a little to get it to work.
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

May 7th, 2007, 04:59 PM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks. I keep getting this message "Object reference not set to an instance of an object." on This line "Dim userId As Guid = CType(Membership.GetUser().ProviderUserKey, Guid)" What do I need to do?
Computergirl
|
|

May 7th, 2007, 05:05 PM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello Imar,
Do I need to add an UserId column to the BlogEntry table in order to do this? or just change the ID column to an uniqueidentfire?
Computergirl
|
|

May 8th, 2007, 01:31 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
quote:"Object reference not set to an instance of an object." on This line "Dim userId As Guid = CType(Membership.GetUser().ProviderUserKey, Guid)"
|
You're probably not logged on then.
Membership.GetUser() returns the current user when logged in or Nothing when you're not logged in. So, when you're not logged in, you try to get the ProviderUserKey from Nothing which won't work.
Quote:
|
quote:Do I need to add an UserId column to the BlogEntry table in order to do this? or just change the ID column to an uniqueidentfire?
|
You seem to be missing some fundamental knowledge about what it is that you want to do, and how to do it.
I think you need to take a step back from the code, take a piece of paper and write things down. Make a few diagrams, draw some classes that are shown in the book as well, and then decide what you need.
If you do that, you can answer questions like this one easily yourself. Think about the question: how would changing the Id column into a Guid help you? Are all your visitors only allowed to post once? How will you clearly identify unique BlogEntries when people can post more than one entry?
So the answer is: no, don't change it, but add it. That way, you have an Id column to uniquely identify the item in the table, and a PostedBy column to get the Guid of the MembershipUser that posted it.
Does this help?
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

May 8th, 2007, 09:42 PM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello Imar,
Your help has been greatly appreciated! I have another question:
I get this message: Specified cast is not valid. On this line: Dim posterId As Guid = CType(myDataRowView("PostedBy"), Guid) How do I fix it.
Sincerely,
Computergirl
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Wrox Blog in C# |
madAlan |
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 |
22 |
June 12th, 2011 04:09 AM |
| Wrox Blog: Viewing individual blog entries |
Tawanda |
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 |
7 |
May 7th, 2007 12:06 PM |
| Login for Wrox Blog |
danielson |
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 |
3 |
March 20th, 2007 02:12 PM |
| Wrox blog suggestions |
nakori |
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 |
3 |
June 15th, 2006 04:35 PM |
| Wrox Blog Admin |
addstravel |
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 |
1 |
April 23rd, 2006 05:41 AM |
|
 |