-->

Thursday, April 9, 2015

How to create new user in ASP.NET 4.5

I have already explain custom registration control in asp.net on my blog. Now,A very simple method provided by the Microsoft in DOTNET Framework 4.5 for create new users. Using "Microsoft.AspNet.Identity" namespace you can create new users also implementing role init. This namespace is available in "Microsoft.AspNet.Identity.Core" assembly. Username and password are the primary field of registration so first of all, we will store the username by the textbox in "IUser" interface.  In this assembly IUser interface property is inherited by the IdentityUser class and this class is inherited by the ApplicationUser class. So we can easily access the UserName property of the IUser interface in ApplicationUser class.

var user = new ApplicationUser() { UserName = UserName.Text };

By this line of code, we can store the unique username in the database using the connection string, which is available in ApplicationDbContext  class. Now after retrieving the username, should go for second step that is store password in UserManager class using Create method( ), which is take some parameters such as

Create(ApplicationUser user, String Password);

Now, Retrieved result will store in IdentityResult class. Using Succeeded property of that class, we will check that username and password.
Now, the complete code is 

var manager = new UserManager();

var user = new ApplicationUser() { UserName = UserName.Text };

IdentityResult result = manager.Create(user, Password.Text);

Code generate the following output

How to create new user in ASP.NET 4.5

  In the next article i will show you how to add custom fields or you can say how to customized it.

How to make connection with the database

If you are creating dynamic application then must be used database. Before open the connection must to create connection string with the engine or database. Various database engine available in the market, which are SQL, MYSQL, ORACLE etc. Each application have own connection string to connect with the database. In this article, we will learn about that.

How to create connection String with SQL in ASP.NET C#

In Code File

using System.Data.SqlClient;

SqlConnection con = new SqlConnection();

con.ConnectionString =ConfigurationManager.ConnectionStrings ["ConnectionString"].ToString ();
con.Open ();
Using SqlConnection class, you can connect your application with database server. This class is exist in System.Data.SqlClient namespace. ConnectionString is the property of that class, in which you should pass some parameter which is mentioned below in web.config file.

In Web.Config file

<connectionStrings>

<add name="ConnectionString" connectionString="Data Source= (LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"
providerName="System.Data.SqlClient" />
</connectionStrings>

You can pass the ConnnectionString directly in the .cs file, but here we use web.config file for security purpose because this file is not rendered on the browser. ConnectionString take some parameters like DataSource( server name), AttachDbFilename (location of the file, where your database file exist), Integrated Security(takes windows based security). You can use Initial Catalog for database file name also username and password in place of  Integrated Security.

How to create connection String in PHP with phpmyadmin

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("studentinfo", $con);
?>

In the above mentioned code, 'mysql_connect' is a method, in which you have to pass name of server, username of the server and password. After creating the connection you should check that is connection is ok using die method. Using 'mysql_select_db' method you can pass the name of the database for updating the data.

How to use app bar in windows store app

Introduction

App bar is a container, which is contain items on it, such as AppBarButtton, AppBarToggleButton, and AppBarSeparator. You can put an app bar at the top of the page, at the bottom of the page, or both. If you want to use app bar, right click on window screen or press window+Z because App bar is hidden by default.

How to add App bar into your application

Step-1 : Assign a AppBar control to the TopAppBar or BottomAppBar property of a Page. like

<Page.TopAppBar>
    <AppBar>
        <!-- Place control here like AppBarButton -->
    </AppBar>
</Page.TopAppBar>

Step-2 : If you want to add App Bar at Bottom, must Assign a AppBar control to the BottomAppBar property of a Page, like


<Page.BottomAppBar>
   <AppBar>
        <!-- Place control here like AppBarButton -->
    </AppBar>
</Page.BottomAppBar>

Let's take an simple example, App Bar with Refresh button

<Page.TopAppBar>
        
        <AppBar>
            
            <AppBarButton Label="refresh" Icon="Refresh" Click="AppBarButton_Click" />
        </AppBar>
    </Page.TopAppBar>

Code Generate the following output

How to use app bar in windows store app

How to customize GroupedItemsPage in windows store Grid app

In previous article, we have already seen about GroupItemsPage. Now, if you want to customize it. Your data source file exist in DataModel folder. Open SampleData.Json file , which is inside in it. Your file look like.

How to customize GroupedItemsPage in windows store Grid app
If you run this code , default output will appear on your window screen. Look Like

How to customize GroupedItemsPage in windows store Grid app

Change first Group1-item1 picture using above mentioned file. You can change here, for change Item image , which is shown in first tile.

    {
        "UniqueId": "Group-1-Item-1",
        "Title": "Item Title: 1",
        "Subtitle": "Item Subtitle: 1",
        "ImagePath": "LightGray.png",
        "Description" : "Curabitur class aliquam vestibulum nam curae maecenas sed integer cras phasellus",
        "Content" : "About first "
      }, 

Change ImagePath for changing image. Before change , must take single image file into your solution explorer.
After change your code will look like

    {
        "UniqueId": "Group-1-Item-1",
        "Title": "Item Title: 1",
        "Subtitle": "Item Subtitle: 1",
        "ImagePath": "jacob.jpg",
        "Description" : "Curabitur class aliquam vestibulum nam curae maecenas sed integer cras phasellus",
        "Content" : "About first "
      },

How to customize GroupedItemsPage in windows store Grid app

How to use TimerPicker control in Windows store app

Introduction

User can pick time easily by the TimerPicker control. You can give input in it by touch, mouse, and keyboard. It is divided in two different interval, such as AM and PM. It is take 24Hourclock bydefault. If you want to show "am" and "pm" with default TimerPicker control, should set ClockIdentifier is 12HourClock.

Default view of Timer Picker control

  <TimePicker HorizontalAlignment="Left" Margin="230,275,0,0" VerticalAlignment="Top"/>

Default view of TimerPicker control in windows store app

After set ClockIdentifier property in TimerPicker control

<TimePicker ClockIdentifier="12HourClock" HorizontalAlignment="Left" Margin="230,275,0,0" VerticalAlignment="Top"/>

After set ClockIdentifier property in TimerPicker control

Example of Time property of TimerPicker control

<TimePicker Time=" 12:00:00" ClockIdentifier="12HourClock" HorizontalAlignment="Left" Margin="230,275,0,0" VerticalAlignment="Top"/>


Example of Header property of TimePicker control

<TimePicker Header="This is you time" Time=" 12:00:00" ClockIdentifier="12HourClock" HorizontalAlignment="Left" Margin="230,275,0,0" VerticalAlignment="Top"/>

Example of Header property of TimePicker control

Example of IsEnabled property of TimerPicker Control

Example of IsEnabled property of TimerPicker Control

Getting Started with Grid App in Windows Store App

Introduction

In the preceding example, we saw getting started with windows store app. Today we will Getting started with grid app. Create a new Grid app project under visual studio 2013 and run this application without any changes. First of all, you will see splash screen on your window screen. Like

Default screen of Grid app in windows screen
Above given snap contains multiple group titles, Group titles contains multiple item title and each item titles having three fields, such as Item picture, Item Title, and item Sub title. When we click on group title , appear new splash screen in windows look like this.
 Splash screen contains group detail page
 Splash screen contains group detail page, which is contain large image with description text(about group title). In right hand side, you can see all item titles with thumbnail image. When we will click on item title , new splash screen will appear on window look like.
 item title , new splash screen
Now, look at in solution explorer, which is contains four .xaml file such as
  1. App.xaml
  2. GroupDetailPage.xaml
  3. GroupedItemsPage.xaml
  4. ItemDetailPage.xaml

If you want to change in all three file then we will implement own code for it. If you want to change app name in windows store then should go for App.xaml file

<x:String x:Key="AppName">Type your application name here</x:String>
For example
<x:String x:Key="AppName">Windows Store App</x:String>

Output Screen

change app name in windows store

How to use Style property in windows store app

Step-1 :  Double-click MainPage.xaml in Solution Explorer to open it.
Step-2 :  In XAML or design view, add a TextBlock with some Text like " Greeting".
Step-3 :  In the Properties Window, Expand the Miscellaneous group and find the Style property.
How to use Style property in windows store app
Step-4 : Click the property marker next to the Style property to open the menu.
Step-5 : In the menu, select System Resource > BodyTextBlockStyle.

How to use Style property in windows store app
when your mouse pointer come to object(TextBlock), a blue outline shows where the TextBlock is so you can select it.

Complete Source code

<Page
    x:Class="App4.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App4"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

        <TextBlock HorizontalAlignment="Left" Margin="184,216,0,0" TextWrapping="Wrap" Text="Greeting" FontSize="20" VerticalAlignment="Top" Height="44" Width="349" Style="{StaticResource BodyTextBlockStyle}"/>

    </Grid>
</Page>
© Copyright 2013 Computer Programming | All Right Reserved