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:
admin
staff
pubic
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.
admin
staff
public
but in the database these items corresponds to,
1 = admin
2 = staff
3 = public
how to insert these corresponding integers for the particular role?
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:
kim jone
Member
7 Points
19 Posts
selecting a page according to the selected item from drop down list
Apr 10, 2012 03:34 AM|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?
duttavr
Contributor
4035 Points
1079 Posts
Re: selecting a page according to the selected item from drop down list
Apr 10, 2012 04:00 AM|LINK
I did a sample code for you. please refer the below code. I think you'll get what you are looking.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : Page { enum UserRole { ADMIN = 1, STAFF = 2, PUBLIC = 3, } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.FillRolesDropDown(); } RegisterUIControls(); } private void RegisterUIControls() { btnLogin.Click += btnLogin_Click; } void btnLogin_Click(object sender, EventArgs e) { UserRole userRole = (UserRole)(int.Parse(ddlRoles.SelectedValue)); this.RedirectPage(userRole); } private void RedirectPage(UserRole userRole) { switch (userRole) { case UserRole.ADMIN: Server.Transfer(PageNames.ADMIN_URL); break; case UserRole.STAFF: Server.Transfer(PageNames.STAFF_URL); break; case UserRole.PUBLIC: Server.Transfer(PageNames.PUBLIC_URL); break; default: break; } } //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"; } }Please Mark as Answer, if it answers you, also correct me if I'm wrong.
Steven Cheng...
Contributor
4187 Points
547 Posts
Microsoft
Moderator
Re: selecting a page according to the selected item from drop down list
Apr 11, 2012 05:44 AM|LINK
Hi Kim,
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
http://msdn.microsoft.com/en-us/library/2y3fs9xs.aspx
#How to add a Login, Roles and Profile system to an ASP.NET 2.0 app in only 24 lines of code http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx
Feedback to us
Microsoft One Code Framework