-->

Sunday, January 26, 2014

Example of Inline coding model in ASP.NET

Code render blocks define the inline code or inline expressions that are executed when a web page is rendered. The inline code is then executed by the server and the output is displayed on the client browser that requested for the page. The code render blocks are capable of displaying information on the client browser without customarily calling the write method. The code render blocks are represented on a page by the <% %> symbols. The code present inside these symbols is executed in the top-down manner. Now, let's put the concept of code render bock into use by creating an application, CodeRenderBlock. This application use a code render block to implement a loop used for changing the text size.

Lets take a simple example, change font size in asp.net using loop

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Change Font size inline code model</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <% for(int i=0;i<6;i++)
           
       { %>
       <font size="<%=i %>" >Hello World ! </font><br />
       <% } %>

    </div>
    </form>
</body>
</html>

Code generate following output

Computer Programming : code render block

About the Folders in MVC Web Application in Visual Studio: Part 4

In MVC application, Views folder represents the pages shown to the user in the unique folder, named according to controller. Means there is one folder for each controller as shown in the following image of solution explorer.

As in image, account folder have some razor pages like login.cshtml, register .cshtml, manage.cshtml and more. Every page have its own action specified in the respective controller discussed in the earlier article.

Views folder MVC Web Application in Visual Studio 2013


These page can be of any type e.g. plain html, classic asp, razor etc. Home view folder contains Index, about and contact pages. Run the application and there are some links like Home, about, contact us. When user click on any of them, the respective action is called and the related view is shown to user.

Further article will show, how to create such type of folders for Model, controller as well as views.

About the Folders in MVC Web Application in Visual Studio: Part 3

Controller folder represents the controller for the MVC application created, which have two controller by default i.e. AccountController and HomeController. The functions/methods defined in these classes are called Action results used to specify some rules for the view related to that action.

Every action have its related view responsible for handling user input. Every controller in MVC application have a suffix Controller as the name shown in the default controller folder. Programmer can also create its own controller by adding new from the right click on this folder.

The following action shows two type of login actions, first is for Get action and second is for Post action. When user request for login, get action requests, after submitting with required credentials it requests for post (HttpPost) action (the second one).

        [AllowAnonymous]
        public ActionResult Login(string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;
            return View();
        }

        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            {
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }

There should be a view named Login to make these actions effective. Like this action the AccountController also have Register action, logout action etc.

Example of CausesValidation property in ASP.NET

CausesValidation: Whether Validation is performed or not , you can check using CausesValidation property,after button click. Bydefault page validation is performed with all control, which is associated with validation control. If CausesValidation is true, page validate all control , which is associated with validation control. If CausesValidation is false , manually validate the control by the user.

Lets Take an Simple Example

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Enter Your Name : 
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:RequiredFieldValidator
            ID="RequiredFieldValidator1" EnableClientScript ="false" ControlToValidate ="TextBox1" runat="server" ErrorMessage="Validate your name"></asp:RequiredFieldValidator><br />
        <asp:Button ID="Button1" runat="server" Text="Button" CausesValidation="False" 
            onclick="Button1_Click" />


    </div>
    <asp:Label ID="Label1" runat="server"></asp:Label>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        RequiredFieldValidator1.Validate();
        if (RequiredFieldValidator1 .IsValid)
        {
            Label1.Text = "Entered Name is " + TextBox1.Text;
 
        }
    }
}

Code Generate the following output

Example of CausesValidation property in ASP.NET

Example of CausesValidation property in ASP.NET

Label control and their properties in ASP.NET, AssociatedControlID example

Introduction

The label control is used to display the text that the user control edit. The Label control exists within the System.Web.UI.WebControls namespace. Here is the class hierarchy of the Label class:
System.Object
    System.Web.UI.Control
       System.Web.UI. WebControls.WebControl
           System.Web.UI.WebControls.Label

Public Properties of the Label Class

AssociatedControlID : Obtains or sets the identifier for a server control the Label control is associated with.
Text : Obtains or sets the text content of the Label control.

Lets take an simple example

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        Label2.Text = "Associated Control Id Example";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
     <div>
        <asp:Label ID="Label1" runat="server" Text="<u>U</u>serName" AccessKey="U" 
             AssociatedControlID="TextBox1"></asp:Label>
    &nbsp;<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Check Data" 
             onclick="Button1_Click" />
        <br />
        <asp:Label ID="Label2" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>

Code Generating the following Output

Label control and their properties in ASP.NET, AssociatedControlID example

Saturday, January 25, 2014

How to make Report using report viewer in asp.net

Introduction 

The reports consist of HTML containing multiple pages of data.

How to design 

There are different steps for designing report using RDLC file. It consists of objects, such as images , table, line etc. Also You can design header and footer inside it. So lets start

Step-1 : Create a Database table into your website.
Step-2 : Add one DataSet (.xsd file) to the solution explorer using 'Add New Item'.
Step-3 : Right Click on your DataSet window , Add tableAdapter to init.

How to make Report using report viewer in asp.net
Step-4 : After adding TableAdapter , make connection to the database , so select database from dropdown menu.
How to make Report using report viewer in asp.net

Step-5: Select ' Use SQL Statements' in given radio buttons, you can select one of radio button from given radio buttons.
How to make Report using report viewer in asp.net

Step-6: Press Query Builder button and make select query. Also press Next button.

How to make Report using report viewer in asp.net

How to make Report using report viewer in asp.net

Step-7 : Choose method to select CheckBoxes , which is bydefault select (don't any changes) , press next button.
How to make Report using report viewer in asp.net


Step-8 : Click to finish button. 
Step-9 : Add 'Report' (Report.rdlc file)  into Solution Explorer using 'Add New Item' 
Step-10 : Right click on your Report file window, insert page header and page footer.
Step-11 : Add One TextBox control to the Page Header from ToolBox. Also write init like " Student Performance details" 
Step-12 : Add one table to the middle selection of rdlc file, now new window will appear on your screen.
Step-13 : In new window, Select DataSource from DropDown menu .

How to make Report using report viewer in asp.net

Step-14 : In table, Select second row of first column, Bind first column from DataTable column (using top right corner icon)
How to make Report using report viewer in asp.net
Step-15 : Similarly again bind all remaining columns.
How to make Report using report viewer in asp.net


Step-16 : Add new web form (Default.aspx page) using Add new Item to the solution explorer
Step-17 : Add Script Manager and Report Viewer control into webform from ToolBox. 
Step-18 :  Choose Report using show smart tag , also select rdlc file 

How to make Report using report viewer in asp.net

Step-19 : Run your Application.
Step Generating the following output onto the browser window.
How to make Report using report viewer in asp.net




Friday, January 24, 2014

Computer Programming : Classification or Type of Data structures, C Programming

Data structures can be classified, keeping in view the way the elements are connected to each other, the way when they are stored in memory or the way further division of a data structure.

Linear and Non-Linear

This type of classification is on the basis of element's connection and placement. When the elements of a data structures are placed in order, means if the second element is placed after the first one, third one after the second one and so on, are called Linear Data Structures otherwise Non-Linear Data Structures. Examples of Non-linear Data Structures: Trees, Graphs etc.

Classification of Data Structure in Computer programming

ARRAY is an ordered collection of similar data elements. So, it is called as Linear Data Structure. The element are arranged in Linear order i.e. one after the other at consecutive memory locations.Similarly LINKED LIST is also a Linear Data Structure Where the elements of List are stored in Linear Order but at different memory locations, the Linear order is maintained by one of the fields of Linked List, called Link field(pointer to next node element).

On the other hand, TREE is a non-linear data structure in which the elements are stored in hierarchical order instead of linear order. In hierarchical order top most node is called root node and it may be connected to zero, one or more than one nodes. So from one element elements of the data structure are placed such that they are adjacent (connected) to more than one element, then the resulting data structure, Which is non-linear one, is called as GRAPH. Graph is a general non-linear data structure and Tree is a restricted Graph.

STACK and QUEUE are specialized data structures where insertion and deletion are restricted. STACK and QUEUE can be implemented either using one-dimensional array or linked list.

Linear data structure are also called as contiguous data structures and non-linear data structures are called as non-contiguous data structure.

Static and Dynamic

This type of classification is on the basis of Memory Allocation. The data structure modeled must be present in memory to use it i.e. memory should be allocated to the data structure to store the data in it. If the memory is allocated to the data structures at the time of compilation of programs where the data structures are used, then such type of data structures are called as static data structures. Compilation of program is translation of source program into an object program. The linear data structure ARRAY is static data structure for which memory is allocated at the time of  compilation.

On the other hand if the memory is allocated at the time of execution of program (While running) for the data structures used in the program are called Dynamic data structures. The linear data structure LINKED LIST is a dynamic data structure for which memory is allocated at the time of execution, means the memory for data structure is allocated as per the user wish at the time of executing the program.

Primitive and Non-Primitive

This type of classification is on the basis of further division. If the data structure is not further divisible to another data structure, then it is called as Primitive data structure and if it is further divisible then it is called as Non-Primitive data structure.

For example the standard data types of C like char, int, float are fall under the category of Primitive data structures where as user defined or derived data types like array, structure are further divisible so they are called Non-Primitive data structure. 
© Copyright 2013 Computer Programming | All Right Reserved