Last post Apr 11, 2012 06:44 AM by Steven Cheng - MSFT
Apr 10, 2012 04:34 AM|kim jone|LINK
I am newbie to asp.net. I am using ASP.NET, C# for creating a website.
i've a dropdown list in my login page. The dropdown contains three items:
the user fills the login form & selects an item from the dropdown list. After clicking on the submit button, the user should be rendered to the page according to the selected item from the drop-down list.
i.e. if the user selects the staff item he/she should be rendered to the staff page "staff.aspx" page. before that all the links in the login page should be disabled.
how can I do it?
in registration page I've to insert the role of the users. I've made a dropdown for it in my webpage.
but in the database these items corresponds to,
1 = admin
2 = staff
3 = public
how to insert these corresponding integers for the particular role?
Apr 10, 2012 05:00 AM|duttavr|LINK
I did a sample code for you. please refer the below code. I think you'll get what you are looking.
public partial class _Default : Page
ADMIN = 1,
STAFF = 2,
PUBLIC = 3,
protected void Page_Load(object sender, EventArgs e)
private void RegisterUIControls()
btnLogin.Click += btnLogin_Click;
void btnLogin_Click(object sender, EventArgs e)
UserRole userRole = (UserRole)(int.Parse(ddlRoles.SelectedValue));
private void RedirectPage(UserRole userRole)
//You can change this function to fill the items from database.
//I hardcoded for demo purpose.
private void FillRolesDropDown()
ddlRoles.Items.Add(new ListItem("admin", UserRole.ADMIN.ToString()));
ddlRoles.Items.Add(new ListItem("staff", UserRole.STAFF.ToString()));
ddlRoles.Items.Add(new ListItem("public", UserRole.PUBLIC.ToString()));
public class PageNames
public static readonly String ADMIN_URL = "Admin.aspx";
public static readonly String STAFF_URL = "Staff.aspx";
public static readonly String PUBLIC_URL = "Public.aspx";
Apr 11, 2012 06:44 AM|Steven Cheng - MSFT|LINK
As duttavr has provided you a detailed sample page on redirecting user based on their selection in the dropdownlist.
I'd suggest you also considering store the current "role" user select when login into the web page(on login page) into some application wide variable. For example, you can use sessionState or database to store a flag variable which indicate the current role
a certain user selected when login. Thus, even if he navigate across multiple pages, you can track the current role he selected without let him reselecting roles in multiple places.
BTW, the ASP.NET profile service is helpful for storing some user specific data/properties:
#ASP.NET Profile Properties Overview
#How to add a Login, Roles and Profile system to an ASP.NET 2.0 app in only 24 lines of code