 |
| ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking 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 Basics 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
|
|
|
|

March 20th, 2009, 12:19 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Members adding information
I have a members section on my website that includes a city contact page where registered users can search for a city and find users who have lived there. The question that I can't seem to answer is how do create a form that allows the users to enter and edit their own information when they are logged in. I have a repeater which shows all of the city contacts, but I have been unable to tailor a details view that will insert based on the member who is signed in. Any ideas would be appreciated as I have been stuck on this for a while.
|
|

March 20th, 2009, 01:43 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I think the first question is: where do you store the data. City is not a standard property of the MembershipUser class so you must be storing it elsewhere. Maybe in Profile or maybe in a custom solution?
Imar
|
|

March 20th, 2009, 03:14 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I set up a profile which includes the member name and the countries that they have lived in. Idealy what I would like to do is have them able to enter their name, email address, and review of the city if they selected the country in their profile. But from what I read in your asp.net 3.5 book, the profile is stored in a cookie and not in a database. Is that correct? I have a separate table for the reviews city_review. I just keep going in circles with the logic.
|
|

March 21st, 2009, 05:33 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
No, the profile is NOT stored in a cookie. What page / section gave you that impression? Profile data is stored in the database, in aspnet_Profile to be exact. When (anonymous) users visit the site, their ID may be stored in a cookie, but the actual data is stored in the database.
The aspnet_Profile is not the perfect table as it's hard to impossible to query data from it directly. E.g. you can't create your own SQL statement to filter all users from a specific city. If that's what you want, look at the Table and Stored Procedure Profile providers that replace the standard Profile engine that stored data in aspnet_Profile with one that allows you to determine where to store the data: http://www.asp.net/downloads/sandbox...vider-samples/
Quote:
|
and review of the city if they selected the country in their profile
|
A review doesn't really sound like Profile data, does it? ANd as such shouldn't be stored in the user's Profile. You're better of storing the reviews in a separate table and store the user's ID in that table as well so you can see who wrote the review.
Quote:
|
I have a separate table for the reviews city_review
|
So what does this table contain? And what do you store in profile? I am a little confused as to what you're trying to accomplish, how your database looks, what you're storing where and so on. Can you elaborate on all that, describing things as clear as possible?
Imar
|
|

March 21st, 2009, 06:34 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I reread the section on the Profile and now understand it more clearly.
Originally, I set up the page as such:
<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True"DataSourceID="SqlDataSource1"DataTextField="Country"DataValueField="Id"AppendDataBoundItems="true"style="text-align: center">
<asp:ListItemValue="">Please select a country</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:WebsiteConnectionString1 %>"SelectCommand="SELECT [Country], [Id] FROM [Countries] ORDER BY [Country]">
</asp:SqlDataSource>
<asp:DropDownListID="DropDownList2"runat="server"DataSourceID="SqlDataSource2"DataTextField="Name"DataValueField="Id"AppendDataBoundItems="true"AutoPostBack="True"Visible="False">
</asp:DropDownList>
<asp:SqlDataSourceID="SqlDataSource2"runat="server"ConnectionString="<%$ ConnectionStrings:WebsiteConnectionString1 %>"SelectCommand="SELECT [Name], [CountryId], [Id] FROM [Cities] WHERE ([CountryId] = @CountryId) ORDER BY [Name]">
<SelectParameters>
<asp:ControlParameterControlID="DropDownList1"Name="CountryId"PropertyName="SelectedValue"Type="Int32"/>
</SelectParameters>
</asp:SqlDataSource></div>
<asp:RepeaterID="Repeater1"runat="server">
<ItemTemplate>
<pclass="Contacts">
<%# Eval("MemberName") %> <br/>
<%# Eval("Email") %> <br/>
<%# Eval("Summary") %>
</p></ItemTemplate>
</asp:Repeater>
The user selects the country and the city list is populated. From the city they select, I have a repeater that presents all of the information that is in the Review table [MemberId] [CityId] [Summary] table by joining it with the Member table [MemberName] [Email] on [MemberId]. However, these tables are located in a database separate from the aspnetdb.
All I want to do is add the ability for a logged in user to add themselves as a contact and be able to edit/delete their information if they already have added themselves as contact but only when logged in as a regisetered user.
|
|

March 21st, 2009, 09:30 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You can always access the currently logged in user like this:
Dim myUser As MembershipUser = Membership.GetUser()
When myUser is notNothing, you can access the ProviderUserKey property which is a Guid:
Dim userId As Guid = CType(myUYser.providerUserKey, Guid)
Alternatively, Context.User.Identity.Name to get the user's name. In both cases, you can use the name / ID to relate the user to your own records.
For more ideas on this: How to use login user name in where clause?
storing the login name in my personal database
Cheers,
Imar
|
|

March 22nd, 2009, 10:19 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
To make it more clear, this is exactlty what I want to happen:
1. User registers for the site.
2. User fills in profile information which contains which countries they have lived in
3. User goes to the contacts page to see what cities have contacts.
4. If they want to become a contact, they can fill out a form: Name, Email, and Review. I would like the name and the email address to be already filled in based on the user and the only thing that I would like them to fill out is the Review.
5. When they submit the review, it is store in the database as not having been approved and an email is sent to the administrator notifying them of a new review awaiting approval.
6. Once the review is approved, the user can go back and edit and or delete only their review.
I already have sets 1 - 3 completed. I am struggling with 4 - 6. What is the best way to accomplish these tasks?
Last edited by areed24; March 22nd, 2009 at 10:40 AM..
|
|

March 22nd, 2009, 10:39 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It doesn't really matter. You can combine them in one database, or keep them separated. I prefer to have everything in a single database named after my project. I then use the aspnet_regsql tool to prepare my database for the ASP.NET provider services.
Not sure what you're asking about countries and cities....'
Imar
|
|

March 23rd, 2009, 03:28 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Is there a way to access the UserId from the Profile and not the UserName? When a logged in user fills out the form to become a city contact, I would like their name and email address to be automatically filled in based on the aspnetMembership table.
|
|
 |