Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a website using Web Form Application (VB.Net) that require user to login before they can upload their picture there. All images that uploaded will be displayed along with the uploader name. I am sure that it using the session to do it but I have no idea how.

What I have tried:

Here is my Default.aspx for displaying images :

HTML
<asp:DataList Width="100%" ID="imgDataList" runat="server" RepeatColumns="4" CellPadding="10">
	<ItemTemplate>
		<table  runat="server" id="tblImgList" border="1" width="100%">
			<tr>
				<td align="center">
					<a id="Link1"  runat="server" href='<%# Eval("Value") %>' target="Default.aspx">
						<asp:Image ID="imgDisp" ImageUrl='<%# Eval("Value") %>' runat="server" style="height :200px ; width :200px ;" />
					</a> 
				</td>
			</tr>
			<tr>
				<td align="center">
					<%# Eval("Text") %>
				</td>
			</tr>
		</table>
	</ItemTemplate>
</asp:DataList>


This is my VB.Net code to display the images :

VB
If Not IsPostBack Then
            Dim filePaths As String() = Directory.GetFiles(Server.MapPath("~/Images/"))
            Dim files As New List(Of ListItem)()
            For Each filePath As String In filePaths
                Dim fileName As String = Path.GetFileName(filePath)
                files.Add(New ListItem(fileName, "~/Images/" + fileName))   'Automatically add pictures in listdata. Displayed using databind
            Next
            imgDataList.DataSource = files
            imgDataList.DataBind()
        End If


I want to replace this code
<%# Eval("Text") %>
and use it to display the Uploader name there instead of the image name.
Posted
v3
Comments
Member 10398773 26-Mar-16 8:15am    
You can get the name of currently logged in user and replace it in your code.Like for example dim user as string then say user=Page.User.Identity.Name

1 solution

If you don't have an idea about Sessions, hen read it first. So, you first need to check if session is there or not. If it exists, you will load the page, else redirect to login or do some action.

Design a login page, where user can provide username and password to login. When user clicks on login, you match these credentials with the stored details in database (which is inserted while registering the user). If matched, you will redirect to a home page or something.

Then you can store the user's name or whatever you want in session and use it anywhere in the app, even on that DataList.
 
Share this answer
 
Comments
dell-gl62m 26-Mar-16 22:41pm    
This is what I did so far <pre lang="vb">Response.Redirect("Default.aspx?UserLoginID=" & gsUserLogin)</pre> (gsUserLogin as user login name declared in module) which will redirect user to the default page while holding the username session. So I tried to pass the session value in Default.aspx like this <pre lang="vb">Dim userSession As String = Request.QueryString("UserLoginID")</pre> so that I could get the current username
So what is the issue?
dell-gl62m 28-Mar-16 23:56pm    
I tried to replace <%# Eval("Text") %> with <label id="lblUserName" runat="server" /> so that I am able to get and display the user login name but I cannot get the label id at code behind. It said that the lblUserName is not declared.
Yes that won't work as that is inside a DataList. DataList will have many rows, so which label to pick? You have to loop through all the rows and inside the loop you can find the control with the label id.
dell-gl62m 29-Mar-16 4:29am    
Is it possible to display the folder name using the <%#Eval()%>? If I put <%#Eval("Text")%> it will get the name of the image. So I am thinking of creating a folder refer to user login name. Each of user will have this folder with their login name as folder name that contain all images that they upload. So when images displayed in DataList, I want to use <%#Eval()%> to display their name. But I am not sure either it's possible or not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900