Friday 29 March 2013

CreateUserWizard control to create user accounts in asp.net membership


CreateUserWizard control to create user accounts in asp.net membershipIntroduction: 


In this article I will explain how to create users using CreateUserWizard using asp.net membership concept.

Description: 

In previous post I explained clearly how to install asp.net membership database schema in SQL Server . After install asp.net membership database 
check your database everything installed and ready to use in our application or not.  

Now open visual studio and create new web application after that drag and drop the new controlCreateUserWizard from Login Controls section into aspx page and check the aspx page code that would be like this 


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Create Users Using CreateUserWizard Control</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
</div>
</form>
</body>
</html>
Now open Web.config file and set database connection settings in web.config 

First set the connectionstring like this 

<connectionStrings>
<add name="dbconnection" connectionString="Data Source=SureshDasari;Initial Catalog=AspMembership;Integrated Security=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
After that write the following code in system.web section

<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider"connectionStringName="dbconnection" applicationName="SampleApplication"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider"connectionStringName="dbconnection" applicationName="SampleApplication"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"connectionStringName="dbconnection" applicationName="SampleApplication"/>
</providers>
</roleManager>
After that run your application and create users by using CreateUserWizard control.

Here the functionality of insert user details and everything will take care by CreatUserWizard no need to write any coding just set the database and set the conditions in web.config file that is enough it will work perfectly.

During the time of create user if you get error like “Password length minimum: 7. Non-alphanumeric characters required: 1.” check this post solve password length minimum: 7 problem. This problem because of our password basically asp.net membership concept will accept the password only if it contains mixed of alphanumeric and special characters.

Demo


If you observe above demo in that we need to enter different options like UserName, password (strong password like mixed of alphanumeric and special characters), Email (Unique Email), Security Question and answer to register new user. 

If we don’t want security question and answer options and we need to allow users to enter his own password without any restrictions for that we need to configure some properties in web.config file likerequiresQuestionAndAnswer="false", minRequiredPasswordLength="6" andminRequiredNonalphanumericCharacters="0" to set those properties check this post solve password length problem

Asp.net filter gridview records with dropdownlist selection | Gridview Filter Expression with dropdownlist using asp.net | Beautiful style for Gridview using css


Asp.net filter gridview records with dropdownlist selection | Gridview Filter Expression with dropdownlist using asp.net | Beautiful style for Gridview using css


Introduction: 

In this article I will explain how to change the appearance of gridview and how to filter gridview records with dropdownlist selection using asp.net.


Description: 

In Previous posts I explained lot of articles regarding 
Gridview. Now I will explain how to implement beautiful looking gridview and filter gridview records with dropdownlist selection using asp.net. To implement this first design the table in database and give name UserInfomation

ColumnName
DataType
UserId
Int(set identity property=true)
UserName
varchar(50)
LastName
varchar(50)
Location
varchar(50)

After completion table creation write some of css classes to change the appearance of gridview and design aspx page like this
 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> Beautiful Gridview theme with Filtering option</title>
<%--Styles to Change the appearance of Girdview --%>
<style type="text/css">
.GridviewDiv {font-size100%font-family'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial,Helevetica, sans-serifcolor#303933;}
Table.Gridview{border:solid 1px #df5015;}
.GridviewTable{border:none}
.GridviewTable td{margin-top:0;padding0vertical-align:middle }
.GridviewTable tr{colorWhitebackground-color#df5015height30pxtext-align:center}
.Gridview th{color:#FFFFFF;border-right-color:#abb079;border-bottom-color:#abb079;padding:0.5em0.5em 0.5em 0.5em;text-align:center
.Gridview td{border-bottom-color:#f0f2da;border-right-color:#f0f2da;padding:0.5em 0.5em 0.5em0.5em;}
.Gridview tr{colorBlackbackground-colorWhitetext-align:left}
:link,:visited { color#DF4F13text-decoration:none }
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="GridviewDiv">
<table style="width420px" border="0" cellpadding="0" cellspacing="1" class="GridviewTable">
<tr >
<td style="width40px;">
UserId
</td>
<td style="width120px;" >
LastName
</td>
<td style="width130px;">
UserName
</td>
<td style="width130px;">
Location
</td>
</tr>
<tr >
<td style="width40px;">
</td>
<td style="width120px;">
</td>
<td style="width130px;">
<asp:DropDownList ID="ddlUserName" runat="server" DataSourceID="dsUserName"DataValueField="UserName" AutoPostBack="true" Width="120px" Font-Size="11px"AppendDataBoundItems="true">
<asp:ListItem Text="All" Value="%"/>
</asp:DropDownList>
</td>
<td style="width130px;">
<asp:DropDownList ID="ddlLocation" runat="server" DataSourceID="dsLocation" DataValueField="Location"AutoPostBack="true" Width="120px" Font-Size="11px" AppendDataBoundItems="true">
<asp:ListItem Text="All" Value="%"/>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="4">
<asp:GridView runat="server" ID="gvdetails" ShowHeader="false" AllowPaging="true" PageSize="10"DataSourceID="dsdetails" AutoGenerateColumns="false" Width="420px"  CssClass="Gridview">
<Columns>
<asp:BoundField DataField="UserId" HeaderText="UserId" ItemStyle-Width="40px" />
<asp:BoundField DataField="LastName" HeaderText="LastName" ItemStyle-Width="120px" />
<asp:BoundField DataField="UserName" HeaderText="UserName" ItemStyle-Width="130px"/>
<asp:BoundField DataField="Location" HeaderText="Location" ItemStyle-Width="130px"/>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
<asp:SqlDataSource ID="dsUserName" runat="server"ConnectionString="<%$ConnectionStrings:dbconnection %>" SelectCommand="Select Distinct UserName from UserInformation"></asp:SqlDataSource>
<asp:SqlDataSource ID="dsLocation" runat="server"ConnectionString="<%$ConnectionStrings:dbconnection %>" SelectCommand="Select Distinct Location from UserInformation"></asp:SqlDataSource>
<asp:SqlDataSource ID="dsdetails" runat="server"ConnectionString="<%$ConnectionStrings:dbconnection %>" SelectCommand="select * from UserInformation" FilterExpression=" UserName Like '{0}%' and Location Like '{1}%'">
<FilterParameters>
<asp:ControlParameter Name="UserName" ControlID="ddlUserName" PropertyName="SelectedValue" />
<asp:ControlParameter Name="Location" ControlID="ddlLocation" PropertyName="SelectedValue" />
</FilterParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
If you observe above code in header section I written css classes by using those we can change the appearance of gridview and written code to bind dropdownlists, gridview and bind the gridview records based on dropdownlists selection.

Here don’t forgot to set the connection string in web.config file here I am getting database connection from web.config file for that reason you need to set the connectionstring in web.config file like this

<connectionStrings>
<add name="dbconnection" connectionString="Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB"/>
</connectionStrings>
Demo

Download sample code attached