4

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

4

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

0

Hide and show multi level menu in jquery


CSS code

<style>
/*menu*/
#menu
{
margin: 0;
background:url(images/menu.png);
background-repeat:no-repeat;
height:45px;
margin-top:-24px;
margin-left:15px;
padding: 0;

}
#menu li
{
float: left;
list-style: none;
font: 12px Tahoma, Arial;

}
#menu .panel
{
position:absolute;
display:none;
text-align:left;
border-top: 1px solid #9D9D9D;
border-bottom: 1px solid #9D9D9D;
background: #A9C251;
padding:7px 7px 7px 7px;
margin:-5px 2px 2px 2px;
}
#menu .panel td
{
background: url(images/arrow.png) no-repeat left ;
padding-left:10px;
}
#menu .panel a
{

color: #24313C;
height:10px;
text-decoration: none;
width: auto;
color:#000;
font-family:Arial, Helvetica, sans-serif;

font-size:12px;
font-weight:bold;
white-space: nowrap;
padding:0px 5px 5px 0px;
float:left;
display:list-item;
margin:10px 10px 10px 10px ;
}
#menu .panel a:hover
{
color:#D8D8D8;

}
#menu li .slide
{
display: block;
background: url(images/divideline.jpg) no-repeat right ;
padding: 15px 12px;
text-decoration: none;
width: 80px;
color:#000;
font-family:Arial, Helvetica, sans-serif;
font-size:13px;
font-weight:bold;
white-space: nowrap;
}
#menu li .slide:hover
{
color:#222;
}

/*end menu*/

</style>

Continue reading

4

C/C++ program that connects to a MySQL server and checks intrusion attempts every 5 minutes


This program is developed in ubuntu gccto execute this program use the following command
“gcc  $(mysql_config –cflags) fmysql.c $(mysql_config –libs)”
for output “./a.out”

C program that connects to a MySQL server and checks intrusion attempts every 5 minutes. If an intrusion attempt is detected beep the internal speaker to alert the administrator.
Continue reading

1

Add SQL parameter at run time using store procedure in c#


Code for add SQL Parameter at run time using store procedure in c#

SqlConnection connection;
SqlCommand command = new SqlCommand();
string connectionstring;
SqlParameter paraName = new SqlParameter();
public void addparameter(string prameterName, string prameterValue)
{
paraName.ParameterName = prameterName;
paraName.Value = prameterValue;
command.Parameters.Add(paraName);
}
0

Set default browser for ASPX page


1) Right click on  .aspx page in “solution explore”.

2) Select “browse with” with menu option.

3) Then “Browse With” window will appear.

4) You can set size of browser window by drop-down list at bottom.

2

Java script for Disable the cut, copy, paste and accepts the number and alphabets only


1) Java script for disable the cut, copy, paste task from the textbox

               a). By Disabling the mouse right click

function no_Cpy_Mouse(event) {
 var isRight = (event.button) ? (event.button == 2) : (event.which == 3);
    if (isRight) {
        alert('Right Click is disable.');
        return false;
    }
    return true;
}

                b). By Disabling the key control

function no_Cpy_byKey(event) {
    var forbiddenKeys = new Array('c', 'x', 'v');
    var keyCode = (event.keyCode) ? event.keyCode : event.which;
    var isCtrl;

    if (window.event)
        isCtrl = event.ctrlKey
    else
        isCtrl = (window.Event) ? ((event.modifiers & Event.CTRL_MASK) == Event.CTRL_MASK) : false;

    if (isCtrl) {
        for (i = 0; i < forbiddenKeys.length; i++) {
            if (forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {
                alert('Please type this for a reason!');
                return false;
            }
        }
    }
    return true;
 }

2. java script for accepts only numbers

function number_only(event, dec) {
     var key;
     var keychar;
     if (window.event) {
         key = window.event.keyCode;
 
     }
     else if (event) {
         key = event.which;
        

     }
     else {
        
         return true;
     }
     keychar = String.fromCharCode(key);
     if ((key == null) || (key == 0) || (key == 8 ) || (key == 9) || (key == 13) || (key == 27)) {
                  return true;
     }
              else if ((("0123456789").indexOf(keychar) > -1)) {

         return true;
     }
     else if (dec && (keychar == ".")) {
         return true;
     }
     else 
         return false;
 
 }

3. java script for accepts only alphabets

function alphabet_only() {

         var keyStroke = (event.which) ? event.which : (window.event) ? window.event.keyCode : -1;
         var returnValue = false;

         if (((keyStroke >= 65) && (keyStroke <= 90)) || ((keyStroke >= 97) && (keyStroke <= 122)))
             returnValue = true;

         if (window.event)
             window.event.returnValue = returnValue;

         return returnValue;
 }

4

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>
0

Check online user IP Address in aspx


Code for trace the online user ip address in aspx
protected void Page_Load(object sender, EventArgs e)
        {
        
string ipadd;
ipadd = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipadd == null)
{
    ipadd = Request.ServerVariables["REMOTE_ADDR"];
}
TextBox1.Text = ipadd;

        }


0

Change aspx Page Title At Runtime


code for set the aspx page title at runtime.

Page.Header.Title = "the current time is:" + DateTime.Now.ToString();

 


1

Drag And Drop in WPF


“This demo will demonstrate how to drag and drop a txt file in the WPF textbox and it show the content of that files”.

 Download: http://www.4shared.com/file/GWB4a3bQ/drg.html

1.     “select the textbox and change it “Allow Drop” property true.”

2.     “write the following code in the textbox “Preview Drag Enter” event. ”

Code:

private void textBox1_PreviewDragEnter_1(object sender, DragEventArgs e)
        {
            bool isCrt = true;</pre>
            if (e.Data.GetDataPresent(DataFormats.FileDrop, true) == true)
            {

                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, true);
                foreach (string file in files)
                {
                    if (File.Exists(file) == false)
                    {
                        isCrt = false;
                        break;
                    }
                    FileInfo info = new FileInfo(file);
                    if (info.Extension != ".txt")
                    {
                        isCrt = false;
                        break;
                    }

                }
            }
            if (isCrt == true)
            {
                e.Effects = DragDropEffects.All;

            }
            else
                e.Effects = DragDropEffects.None;
            e.Handled = true;
        }

3. “write the following code in the textbox preview drop event function.”

Code:

private void textBox1_PreviewDrop(object sender, DragEventArgs e)
        {

            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, true);
            foreach (string file in files)
                textBox1.Text += File.ReadAllText(file);
            e.Handled = true;
          }
0

Timer in WPF


  In this demo, Demonstrate you how to use timer in WPF(Window Presentation Foundation). For using the timer first we need to use this namespace “using System.Windows.Threading;” .Create one “DispatcherTimer()” object called “Timer”.

Download:   “http://www.4shared.com/file/-1Z0xy1_/timer.html ”

       

Write the following code :

Code :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;
using System.Windows.Threading;

namespace timer

{

    /// <summary>

    /// Interaction logic for MainWindow.xaml

    /// </summary>

    ///

    public partial class MainWindow : Window

    {

        public MainWindow()

        {

            InitializeComponent();

            Timer = new DispatcherTimer();

        }

        private DispatcherTimer Timer;

       // public event Action DoSomething;

        private int _timesCalled = 0;

        public void timer_Start(int PeriodInSeconds)

        {

            Timer.Interval = TimeSpan.FromSeconds(PeriodInSeconds);

            Timer.Tick += timer_Task;

            _timesCalled = 0;

            Timer.Start();

        }

        public void timer_Stop()

        {

            Timer.Stop();

        }

        int i;

        private void timer_Task(object sender, EventArgs e)

        {

            listBox1.Items.Add(Convert.ToString(DateTime.Now));

        }

        private void button1_Click(object sender, RoutedEventArgs e)

        {

            if (textBox1.Text.Length > 0)

            {

                listBox1.Items.Clear();

                timer_Start(Convert.ToInt32(textBox1.Text));

            }

            else

                MessageBox.Show("set time");

        }

        private void button2_Click(object sender, RoutedEventArgs e)

        {

            Timer.Stop();

        }

    }

}

1

Vehicle insurance project in c#.net


vehicle insurance project is a mini college project .you can download this project:

Download:  http://www.4shared.com/file/Z4HxQ7Z0/vcl_insurence_prj.html

The product entitled “automation” aim at automation of many processes of Vehicle Insurance. Current manual system that is employed is extremely. Laborious and quite in adequate it only maker the process more difficult and hard. Main purpose of this software is to reduce to manpower, paperwork and provide the security from unauthorized access. It helps in producing difficult kinds of report required in showroom for different managerial aspects.

4

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();

    }

}