• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

Display differnt links to different users

I would like some help on how can I displat different links to different user.

Ex. If you go to my website, you should not be able to see the link edit profile, unless you login. And I have 2 differents type of user, and they should have different links.

I'm using access db.
3 Solutions
Jeff CertainCommented:
The first is usually done by using a different header within the secure folder (i.e. the one that contains the pages users access after they've logged in).

The second will require dynamically setting the links on the header. You can do this simply enough by creating all the links for both of the users in the header, and hiding the links you don't want when the header (ascx file) loads.
EnnioAuthor Commented:
So I got a book here but It's not a good one..

So I should create a ascx file for each one action I want to happened (like if a user is a guest do not display any link, if the user is level 1 display some link,etc...)
In this case I'd use some table to contain ALL of the links you're using. It would consis of four columns: ID Name URL Group. If link is accessible only by group #1 then Group column would contain value 1, if link is accessible only by group #2 then Group column would contain value 2 and if link is accessible for both groups Group colmun would contain value 3.

Then, in a mentioned above webusercontrol (ascx) I'd place datagrid(or datalist) whitch would contain a template column with a Hyperlink WebControl in it. The last thing to do is to select links from a table depending on a visiting user's group and to bind the selected recordset to datagrid. Hyperlink's NavigateUrl ant Text properties would reflect Tables Name and URL columns' values respectivelly.

Hope this will help
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

The question is why you want to show two different URL to users?  If user has two different role assingned you should better append a variable int he querystring and based on that call the apporpriate funcitons.

For example:

When administrator logs in define a Session variable access level in the login page:

Session["USER_ROLE"] = "ADMIN";

When a normal user logs in:

Session["USER_ROLE"] = "USER";

Now in the URL:

<a href="MyProfile.aspx?UserID=1&UserRole=<%=Session["USER_ROLE"]%>">Profile</a>

You should be able to achive the functionality in this way rather than defining the URL for a user in the database.  This approach will also add a consistency to your application.

HTH, Nauman.
EnnioAuthor Commented:
I'm getting this error using .ascx file

I have a page_load that need to popula some fields that are in my .ascx file (CAN I DO THAT?)

I'm posting my codes here.

My .ASCX file (this is just a test, so I only have these 2 fields)

First Name: <asp:TextBox ID="txtfname" runat="server" /><br />
Last Name: <asp:TextBox ID="txtlname" runat="server" /><br />


My aspx page

<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Register TagPrefix="bsf" TagName="babysitterform" src="babysitter.ascx" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script language="vb"  runat="server">
Sub Page_Load( S As Object, E As EventArgs)
      If Not isPostBack Then
            Dim myConn As OleDbConnection
            Dim myComm As OleDbCommand
            Dim myData As OleDbDataReader
            myConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/database/babysitter.mdb") & ";")
            babysitterform1.txtfname.Text = "Ennio"
      End If
End Sub
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<form runat="server">
<bsf:babysitterform ID="babysitterform1" runat="server" />

EnnioAuthor Commented:
and here is the error

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30390: '_ASP.babysitter_ascx.txtfname' is not accessible in this context because it is 'Protected'.

Source Error:


Line 7:              myConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/database/babysitter.mdb") & ";")
Line 8:              myConn.Open()
Line 9:              babysitterform1.txtfname.Text = "Ennio"
Line 10:             
Line 11:             myConn.Close()

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now