Use unobtrusive validator with AngularJs


Create a Directive called ‘validateit’ in Angularjs
and call ‘validateit’ directive in submit button.

PsAdminApp.directive('validateit', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
element.on("click", function (e) {
$('form').each(function () {
var $el = $(this);
$el.data('validator', null);

$.validator.unobtrusive.parse($el);
});
});
}}
});

Submit button code

<input type="submit" name="submit" value="submit" validateit />

ASP.net,C# Code For Sending An Email using Gmail and Hotmail


ASP.net,C# Code Send Mail From GMail Account

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;
public partial class _Default : System.Web.UI.Page
{
  protected void btn_Click(object sender, EventArgs e)
    {
       MailMessage MyMailMessage = new MailMessage("FromMailId@gmail.com", "TOMailId@hotmail.com",
"write your subject Here ", "Hi,This is the test message ");
MyMailMessage.IsBodyHtml = false;
NetworkCredential mailAuthentication = new NetworkCredential("FromMailId@gmail.com", "Password");
        SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587);
        mailClient.EnableSsl = true;
        mailClient.UseDefaultCredentials = false;
        mailClient.Credentials = mailAuthentication;
        mailClient.Send(MyMailMessage);
     }
}

Continue reading

Data Grid View With Textbox And Edit (Insert, Update, Delete) Option


In this demo use a grid view ,text boxes, buttons(Add, delete, update, cancel ) and Ajax calendar extender.

Use one table called “empinfo” it has 4 field

  1.       Id it is integer type and identity
  2.       Name it is nvarchar(100) for employee name
  3.       email_id it is nvarchar(300) for employee email id
  4.       dob it is nvarchar(20)  for employee date of birth

Continue reading

AJAX Tab Control In ASP.net


In Ajax Tab control we must declare the following things

1)  TabContainer
2)  TabPanel
3)  ContentTemplate
4)  HeaderTemplate

Tab container
          
Tab container creates a group of Tabs which is able to handle page content. Tab panel is organizer of all tab panels.

Tab Panel
               
Tab panel has two parts HeaderText or HeaderTemplate and ContentTemplate that’s help to define the content.

Content Template
               Content Template is use to define the content in the tab panel.

HeaderText or HeaderTemplate
               HeaderTemplate or HeaderText use to define the header text of the panel or templet.

<ajaxToolkit:TabContainer ID="TabContainer1" runat="server">
   <ajaxToolkit:TabPanel runat="server" ID="pl_gen" HeaderText="General Details">
      <ContentTemplate>
            General Details
      </ContentTemplate>
   </ajaxToolkit:TabPanel>
 <ajaxToolkit:TabPanel runat="server" ID="pl_sal" HeaderText="Salary & Passport Info">
      <ContentTemplate>
           Salary & Passport Details.
      </ContentTemplate>
 </ajaxToolkit:TabPanel>
 <ajaxToolkit:TabPanel runat="server" ID="pl_dl" HeaderText="DL Info">
      <ContentTemplate>
          Driving License Details Details,PAN card number.
      </ContentTemplate>
 </ajaxToolkit:TabPanel>
 <ajaxToolkit:TabPanel runat="server" ID="pl_edu" HeaderText="Education">
      <ContentTemplate>
           Education Details Details.
      </ContentTemplate>
 </ajaxToolkit:TabPanel>
 <ajaxToolkit:TabPanel runat="server" ID="pl_employ" HeaderText="Previous Employment">
      <ContentTemplate>
          Previous Employment Details.
      </ContentTemplate>
 </ajaxToolkit:TabPanel>
 <ajaxToolkit:TabPanel runat="server" ID="pl_training" HeaderText="Training Info">
      <ContentTemplate>
          Training Details.
      </ContentTemplate>
 </ajaxToolkit:TabPanel>
 <ajaxToolkit:TabPanel runat="server" ID="pl_address" HeaderText="Address Info">
      <ContentTemplate>
          Permanent Address,Current Address,Emergency Contact, Details.
      </ContentTemplate>
 </ajaxToolkit:TabPanel>
 <ajaxToolkit:TabPanel runat="server" ID="pl_fl_info" HeaderText="Family Info">
      <ContentTemplate>
          Family Related Information
      </ContentTemplate>
 </ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>

Database connection with asp.net using c#


In this demo use the asp component Ajax, grid view, textboxes, buttons, table.

Download This Demo: http://www.4shared.com/file/_7bHhSY7/WebSite1.html

1)      First add the Ajax component .in default.aspx  you find it in the Ajax extensions

                1)      Add “script manager”.

                2)      Add “update panel”

                3)      Within “update panel” add “content template tag”.

                4)      In content template add the following component buttons, textboxes and lable and the grid view and rename that buttons insert, update, delete and view record.

2)       Open the default.cs file and define the following global variables

string qry;
string connection = "Data Source=.;Initial Catalog=info;Integrated Security=True";
 SqlConnection con;
SqlCommand cmd;
SqlDataSource sds = new SqlDataSource();

 3)    Right click on the insert button and write the following code:


qry = "insert into customer values('" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "')";

        con = new SqlConnection(connection);

        cmd = new SqlCommand(qry, con);

        con.Open();

        cmd.ExecuteNonQuery();

        con.Close();

       Label1.Text = "Record Inserted.";

4)      Right click on the “view record” button and write the following code for display the record in grid view :

qry = "select * from customer";

       sds = new SqlDataSource(connection, qry);

GridView1.DataSource = sds;

GridView1.DataBind();

 

 

2)      For update button right click on the button and write the following code in it:

qry = "update customer set name='" + TextBox2.Text + "',phone='" + TextBox3.Text + "',email='" + TextBox4.Text + "'where id='" + TextBox1.Text + "'";

con = new SqlConnection(connection);

cmd = new SqlCommand(qry, con);

con.Open();
cmd.ExecuteNonQuery();

 

 

3)      For delete the record write the following code:

qry = "delete from customer where id='" + TextBox1.Text + "'";

        con = new SqlConnection(connection);

        cmd = new SqlCommand(qry, con);

        con.Open();

        cmd.ExecuteNonQuery();

        con.Close();

 

Default.aspx code:

  <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <style type="text/css">
        .style1
        {
            width: 152px;
        }
        .style2
        {
            width: 644px;
        }
    </style>
</asp:Content>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <table style="width: 100%;">
        <tr>
            <td>
                &nbsp;
                ID</td>
            <td>
                &nbsp;
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:Label ID="Label2" runat="server" Text="use id for search"></asp:Label>
            </td>
            <td>
                <asp:Label ID="Label1" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
                name</td>
            <td>
                &nbsp;
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                    ControlToValidate="TextBox2" ErrorMessage="Name is requird"></asp:RequiredFieldValidator>
            </td>
         
        </tr>
        <tr>
            <td>
                &nbsp;
                phone number</td>
            <td>
                &nbsp;
                <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                    ControlToValidate="TextBox3" ErrorMessage="Phone number is requird"></asp:RequiredFieldValidator>
            </td>
          
        </tr>
        <tr>
            <td>
                &nbsp; E-mail</td>
            <td>
                &nbsp;
                <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
                    ControlToValidate="TextBox4" ErrorMessage="Email is requird"
                    ForeColor="#CC0000"></asp:RequiredFieldValidator>
            </td>
         
        </tr>
        <tr>
            <td>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</td>
            <td align="left">
              
                <asp:Button ID="Button1" runat="server" Text="Insert" onclick="Button1_Click" />
                <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="View record" />
                <asp:Button ID="Button4" runat="server" Text="Update" onclick="Button4_Click" />
                <asp:Button ID="Button3" runat="server" Text="Delete" onclick="Button3_Click" />
                <br />
                <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
                    GridLines="None">
                    <AlternatingRowStyle BackColor="White" />
                    <EditRowStyle BackColor="#2461BF" />
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#EFF3FB" />
                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                    <SortedAscendingCellStyle BackColor="#F5F7FB" />
                    <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                    <SortedDescendingCellStyle BackColor="#E9EBEF" />
                    <SortedDescendingHeaderStyle BackColor="#4870BE" />
                </asp:GridView>
            </td>
        </tr>
     
    </table>
</ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

 

Default.cs code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page

{

    string qry;

    string connection = "Data Source=.;Initial Catalog=info;Integrated Security=True";

    SqlConnection con;

    SqlCommand cmd;

    SqlDataSource sds = new SqlDataSource();

    protected void Button2_Click(object sender, EventArgs e)

    {

        qry = "select * from customer";

        sds = new SqlDataSource(connection, qry);

        GridView1.DataSource = sds;

        GridView1.DataBind();

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

        qry = "insert into customer values('" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "')";

        con = new SqlConnection(connection);

        cmd = new SqlCommand(qry, con);

        con.Open();

        cmd.ExecuteNonQuery();

        con.Close();

        Label1.Text = "Record Inserted.";

    }

    protected void Button4_Click(object sender, EventArgs e)

    {

        qry = "update customer set name='" + TextBox2.Text + "',phone='" + TextBox3.Text + "',email='" + TextBox4.Text + "'where id='" + TextBox1.Text + "'";

        con = new SqlConnection(connection);

        cmd = new SqlCommand(qry, con);

        con.Open();

        cmd.ExecuteNonQuery();

    }

    protected void Button3_Click(object sender, EventArgs e)

    {

        qry = "delete from customer where id='" + TextBox1.Text + "'";

        con = new SqlConnection(connection);

        cmd = new SqlCommand(qry, con);

        con.Open();

        cmd.ExecuteNonQuery();

        con.Close();

    }

}

 

Website configuration create new user in aspx


In asp web project you can configure your website and create the new account go to menu and click on the website>>asp.net configuration. Click the security tag and click “Select authentication type”. And click the radio button front of the “From the internet.” And then create the new account and click the done button. Create the new user.

Master page,treeview,sitemap,css in ASPX.net


Master page is use to give one design and give look and feel to website. By using the master page design it will apply to other webpages which is design under the master page. The advantage, if we want to design many pages with same design, just design the master page and it will apply to other pages automatically.we going to design this page using the master page.

You can download this example.

1)      Master page called main.master.

2)      Three Aspx pages (Feedback.aspx, contactus.aspx, help.aspx).

3)      Asp tree view component.

4)      Sitemap (web.sitemap)

5)      Image tag.

6)      CSS style sheet.

first we design the master page:

1)      Open the new project and give it name “masterpage” remember you must select the “asp.net empty web application project”,Right click on your project and select the ‘add new item’.one window will be open then select the master page. Rename it as ‘main. Master’.Right click on your project add new folder and rename to “style” in style write the following style code. And add this style page in master page.goto to format << attach style sheet.


body {

   background-color: #FFFFFF;

   margin: 0px;

   padding: 0px;

   font-family: Verdana, Arial, Helvetica, sans-serif;

   font-size: 12px;

   line-height: 1.5em;

}

#header

{

   text-align: center;

    width: 740;

}

#left

{

    margin: auto auto auto 315px;

    float: left;

    width: 137px;

    background-image: url('../images/page-bg.gif');

}

#contant

{

float:right;

width:388px;

background-color:White;

margin:10px 400px auto auto;

}

Now agin go to solution explorer and add new item.this time we select the web.sitemap file.
Web.sitemap is nothing but a XML file that contain the hirarical from of information of your website related files.”
2)  drag a tree view control from toolbax and add it in you master page now your code will look like this.


        <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1"></asp:TreeView>

         <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />

3) Note that in master page we have not done changes in the contantplace holder.
we just give the look and field in the contantplace holder by give the div tag,style.

4) create a new folder called pages which is going to store all web pages.now create the create the new aspx webpage in pages folder.right click in the pages folder and add new item.now click the web page using the master page give the page name help or if using the VWD click on master page,click ok button and then select the master page and click ok button,create two more pages with same steps called “feedback,contact us”.

5) Now write the code inside the  asp contant tag in the contat us page,your contact us page will look like that.

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

web address:infynet.wordpress.com

</asp:Content>

6) Now open your web.sitemapfile and write the following code:

<siteMapNode url="" title="MENU"  description="">

        <siteMapNode url="pages/contact us.aspx" title="contact us"  description="contact us" />

        <siteMapNode url="pages\help.aspx" title="help"  description="May i help u" />

      <siteMapNode url="pages\feedback.aspx" title="feedback"  description="send feedback" />

    </siteMapNode>