Showing posts with label ASP.NET C#. Show all posts
Showing posts with label ASP.NET C#. Show all posts

Sunday, April 12, 2020

Calculator sample application using asp.net # with validations

Some of the sample screenshots for calc web application assignment 
Step – 1C:\student\Step 4.PNG
Step 2C:\student\Step 3.PNG

Step 3C:\student\Step 5.PNG
Step 4C:\student\Step 3.PNG
Step 5C:\student\Step 2.PNGStep 6C:\student\step 1.PNG
Step 7C:\student\Step 7.PNG

Wednesday, April 1, 2020

Top 10 Interview Questions & Answers of ASP.Net C#

What is ASP.NET?


ASP.NET was developed in that response to the problems that developers have with classic ASP. since it is in such widely used, Microsoft ensures that SP script executes without modification on a machine with the Dot Net Framework( The ASP engine, ASP.DLL, Is not modified when installing the Dot Net Framework). Thus, IIS can house both ASP and ASP.NET scripts on the same machine.

Advantages of ASP.NET:

Separation of God from HTML: To make a clean sweep, with ASP.NET you have the ability to completely separate layout and business logic. This makes it much easier for teams of programmers and designers to collaborate efficiently.
Support for compiled languages: developer can use VB.NET and access features such a strong typing and object-oriented programming. Using compiled languages also means that ASP.NET pages do not suffer the performance penalties associated with interpreted code. ASP.NET Pages are precompiled to bytecode and Just In Time (JIT) compiled when first requested. The subsequent request is directed to the fully compiled code which is cached under the source changes.
Use services provided by the .Net Framework: The .NET Framework provides a class library that can be used by your application. Some up the classes help you with input/ output, assist operating system services, data access or even debugging.
Graphical Development Environment: Visual Studio .NET provides a very rich development environment for web developers. You can drag and drop controls and their properties the way you do in Visual Basic 6 and you have full IntelliSense support, not only for your code but also for HTML and XML.
State management: To refer to the problems mentioned before, ASP.NET provides a solution for session and application state management. The state information can, for example, be kept in memory of stored in the database. It can be shared across web forms, and state information can be recovered even if the server fails or the connection breaks down.

ASP.NET overview

Here are some points that give a quick overview of ASP.NET:
ASP.NET provides services to allow the creation, deploy, and execute application and Web Services.
Like ASP, ASP.NET is a server-side technology.
Web applications are built using web forms. ASP.NET comes with built-in web form controls, which are responsible for generating the user interface. The mirror typical HTML widgets like text boxes or buttons. If these controls do not fit your needs, you are free to create your own user controls.
Web forms are designed to make building web-based applications as easy as building Visual Basic applications.

2. What are the different validators in ASP.NET?


ASP.NET validation controls define an important role in validating the user input data. Whenever you will give the input, it must always be validated before sending it across to various layers of an application.If we get the user input with validation, then chances are that we are sending the wrong data. So, meditation is a good idea to do whenever we are taking input from the user.

There are the following two types of validation in ASP.NET:
Client-Side Validation
Server-Side Validation
Client-Side Validation: When validation is done on the client Browser, then it is known as Client-Side Validation. We use JavaScript to do the Client-Side Validation.

Server-Side Validation: When Validation occurs on the server, then it is known as Server-Side Validation. It is a secure form of validation. The main advantage of Server Side Validation is if the user somehow bypasses the client-side validation we can still catch the problem on the server-side.

The following are the validation controls in ASP.NET:
RequiredFieldValidator control
CompareValidator control
RangeValidator control
RegularExpressionValidator control
CustomFieldValidator control
ValidationSummary

3. What is View State?


View State is the method To preserve the value of the page and control between round trips. It is a Page-Level state management technique. View State is turned on by default and normally serializes the data in every control on the page regardless of whether it is actually used during a post-back.

A web application is stateless. It means that a new instance of a page is created every time when we make a request to the server to get the page and after the round trip our page has been lost immediately.

Features of View State:
There are a few features of view state:
Returns the value of the Control after postback without using a session.
Stores the value of Pages and Control properties defined in the page.

Create a custom view state provider that lets you store view state information in a SQL Server Database or in another data store.

Advantages of ViewState:


Easy to implement.
No server resources are required: The view state is contained in a structure within the page load.
And has a security feature: It can be encoded uncompressed or Unicode implementation.

Saturday, November 21, 2015

How to apply pagin and sorting in gridview in asp.net

For applying paging and shorting follow some steps.
Step No -

First we will create a database Demodatabase.
Now create table Demo.


3. Now I am going for design part<%@ Page Language="C#" AutoEventWireup="true" CodeFile="gridview_controls.aspx.cs" Inherits="gridview_controls" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <div style="font-size: 20px; font-family: Verdana"> <u> Gridview Paging and Sorting</u> <br /> <br /> </div> <div> <asp:GridView ID="GridVwPagingSorting" runat="server" AutoGenerateColumns="False" Font-Names="Verdana" AllowPaging="True" AllowSorting="True" PageSize="5" Width="75%" OnPageIndexChanging="PageIndexChanging" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" OnSorting="Sorting" BackColor="White" CellPadding="4" GridLines="Horizontal"> <PagerStyle BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" BackColor="#336666" ForeColor="White" HorizontalAlign="Center" /> <FooterStyle BackColor="White" ForeColor="#333333" /> <HeaderStyle Height="30px" BackColor="#336666" Font-Size="15px" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Bold="True" ForeColor="White" /> <RowStyle Height="20px" Font-Size="13px" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" BackColor="White" ForeColor="#333333" /> <Columns> <asp:BoundField DataField="Emp_id" HeaderText="ID" SortExpression="Emp_id" /> <asp:BoundField DataField="Emp_Name" HeaderText="Name" SortExpression="Emp_Name" /> <asp:BoundField DataField="Emp_job" HeaderText="Title" SortExpression="Emp_job" /> <asp:BoundField DataField="Emp_Dep" HeaderText="Department" SortExpression="Emp_Dep" /> </Columns> <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F7F7F7" /> <SortedAscendingHeaderStyle BackColor="#487575" /> <SortedDescendingCellStyle BackColor="#E5E5E5" /> <SortedDescendingHeaderStyle BackColor="#275353" /> </asp:GridView> </div> <div style="color: Green; font-weight: bold"> <br /> <i>You are viewing page <%=GridVwPagingSorting.PageIndex + 1%> of <%=GridVwPagingSorting.PageCount%> </i> </div> </div> </form> </body> </html>

4. Code behindusing System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Web.UI.WebControls; public partial class gridview_controls : System.Web.UI.Page { string Sort_Direction = "Emp_Name ASC"; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ViewState["SortExpr"] = Sort_Direction; DataView dvEmployee = Getdata(); GridVwPagingSorting.DataSource = dvEmployee; GridVwPagingSorting.DataBind(); } } private DataView Getdata() { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString())) { DataSet dsEmployee = new DataSet(); string strSelectCmd = "SELECT * FROM employee"; SqlDataAdapter da = new SqlDataAdapter(strSelectCmd, conn); da.Fill(dsEmployee, "Employee"); DataView dvEmp = dsEmployee.Tables["Employee"].DefaultView; dvEmp.Sort = ViewState["SortExpr"].ToString(); return dvEmp; } } protected void PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e) { GridVwPagingSorting.PageIndex = e.NewPageIndex; DataView dvEmployee = Getdata(); GridVwPagingSorting.DataSource = dvEmployee; GridVwPagingSorting.DataBind(); } protected void Sorting(object sender, System.Web.UI.WebControls.GridViewSortEventArgs e) { string[] SortOrder = ViewState["SortExpr"].ToString().Split(' '); if (SortOrder[0] == e.SortExpression) { if (SortOrder[1] == "ASC") { ViewState["SortExpr"] = e.SortExpression + " " + "DESC"; } else { ViewState["SortExpr"] = e.SortExpression + " " + "ASC"; } } else { ViewState["SortExpr"] = e.SortExpression + " " + "ASC"; } GridVwPagingSorting.DataSource = Getdata(); GridVwPagingSorting.DataBind(); } }

5. Now Debug

What do you think ?


Give me feedback by comment.


I hope it is helpfull for you.

How to send multiple mail in asp.net


We will learn How to send multiple mail in asp.net.
Follows some steps-
Step 1- Create database.
Step 2-Create Table

Step 3-
Design Part
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="CS" %>

<!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>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
        table
        {
            border: 1px solid #ccc;
        }
        table th
        {
            background-color: #CCE5FB;
            color: #333;
            font-weight: bold;
        }
        table th, table td
        {
            padding: 5px;
            border-color: #ccc;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical">
    <AlternatingRowStyle BackColor="#DCDCDC" />
    <Columns>
        
        <asp:BoundField DataField="FirstName" HeaderText="First Name" ItemStyle-Width="150" >
<ItemStyle Width="30px"></ItemStyle>
        </asp:BoundField>
        <asp:BoundField DataField="LastName" HeaderText="Last Name" ItemStyle-Width="150" >
       
<ItemStyle Width="150px"></ItemStyle>
        </asp:BoundField>
       
        <asp:BoundField DataField="UserName" HeaderText="User Name" ItemStyle-Width="150" >
<ItemStyle Width="150px"></ItemStyle>
        </asp:BoundField>        
        
        <asp:BoundField DataField="Gender" HeaderText="Gender" ItemStyle-Width="30" >
<ItemStyle Width="30px"></ItemStyle>
        </asp:BoundField>
        <asp:BoundField DataField="Address" HeaderText="Address" ItemStyle-Width="150" >
<ItemStyle Width="150px"></ItemStyle>
        </asp:BoundField>
        <asp:TemplateField HeaderText="Email">
            <ItemTemplate>
                <asp:HyperLink ID="lnkEmail" runat="server" Text='<%# Eval("Email") %>' NavigateUrl='<%# Eval("Email", "mailto:{0}") %>' />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="chkSelect" runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
    <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
    <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F1F1F1" />
    <SortedAscendingHeaderStyle BackColor="#0000A9" />
    <SortedDescendingCellStyle BackColor="#CAC9C9" />
    <SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
<br />
<asp:Button Text="Send Bulk Email" runat="server" OnClick = "SendBulkEmail" />
    </form>
</body>
</html>
Step - 4
Code behind-
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Data;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Configuration;

public partial class CS : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DemoConnection"].ConnectionString);
        if (!this.IsPostBack)
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("Select * From _Demo", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();
            con.Close();
        }
    }

    protected void SendBulkEmail(object sender, EventArgs e)
    {
        //Create a temporary DataTable
        DataTable dtCustomers = new DataTable();
        dtCustomers.Columns.AddRange(new DataColumn[2] { new DataColumn("Name", typeof(string)),
                        new DataColumn("Email",typeof(string)) });

        //Copy the Checked Rows to DataTable
        foreach (GridViewRow row in GridView1.Rows)
        {
            if ((row.FindControl("chkSelect") as CheckBox).Checked)
            {
                dtCustomers.Rows.Add(row.Cells[2].Text, (row.FindControl("lnkEmail") as HyperLink).Text);
            }
        }

        string subject = "Welcome Email";
        string body = "Hello {0},<br /><br />Welcome to SoftgoWay Techonology<br /><br />Thanks.";

        //Using Parallel Multi-Threading send multiple bulk email.
        Parallel.ForEach(dtCustomers.AsEnumerable(), row =>
        {
            SendEmail(row["Email"].ToString(), subject, string.Format(body, row["Name"]));
        });
    }

    private bool SendEmail(string recipient, string subject, string body)
    {
        MailMessage mm = new MailMessage("demo@gmail.com", recipient);
        mm.Subject = subject;
        mm.Body = body;
        mm.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        NetworkCredential NetworkCred = new NetworkCredential();
        NetworkCred.UserName = "softgowaytechnology@gmail.com";
        NetworkCred.Password = "demo@12345";
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587;
        smtp.Send(mm);
        Response.Write("<script>alert('Mail sent successfully');</script>");       
        return true;
    }
}
Step - 5
Build and debug-

What do you think about this article.

Give me feedback  by comments...

Rewrite whole Web Site System and Sub System with data migration to new system.

Can you please share me your skype id or whats up number for better communications  my skype id is - jitendra.tech  whats up - +919617741414...