Share Blog

Monday, October 27, 2014

How to make Contact Page in Asp.net




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

<!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>
    <table border = "0" style="width: 409px">
    <tr>
        <td>
            <asp:Label ID="Label1" runat="server" Text="Name*"></asp:Label><br />
        </td>
        <td>
            <asp:TextBox ID="txtName" runat="server" ValidationGroup = "contact"></asp:TextBox><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
             ControlToValidate = "txtName"></asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label2" runat="server" Text="Subject*"></asp:Label><br />
        </td>
        <td>
            <asp:TextBox ID="txtSubject" runat="server"></asp:TextBox><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
             ControlToValidate = "txtSubject"></asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="Label3" runat="server" Text="Email*"></asp:Label><br />
        </td>
        <td>
            <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox><br />
            <asp:RegularExpressionValidator id="valRegEx" runat="server"
            ControlToValidate="txtEmail"
            ValidationExpression=".*@.*\..*"
            ErrorMessage="*Invalid Email address."
            display="dynamic">
            </asp:RegularExpressionValidator>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*"
            ControlToValidate = "txtEmail"></asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td valign = "top" >
            <asp:Label ID="Label4" runat="server" Text="Body*"></asp:Label>
        </td>
        <td>
            <asp:TextBox ID="txtBody" runat="server" TextMode = "MultiLine" ></asp:TextBox><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="*"
            ControlToValidate = "txtBody"></asp:RequiredFieldValidator>
        </td>
    </tr>
     <tr>
        <td></td>
        <td>
            <asp:FileUpload ID="FileUpload1" runat="server" />
       </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <asp:Button ID="btnSend" runat="server" Text="Send" OnClick="btnSend_Click" />
       </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <asp:Label ID="lblMessage" runat="server" Text="" ForeColor = "Green"></asp:Label>
       </td>
    </tr>
</table>
    </div>
    </form>
</body>
</html>

default.aspx.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.Net;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        MailMessage mm = new MailMessage(txtEmail.Text,"tajpg2013@gmail.com");
        mm.Subject = txtSubject.Text;
        mm.Body = "Name: " + txtName.Text + "<br /><br />Email: " + txtEmail.Text + "<br />" + txtBody.Text;
        if (FileUpload1.HasFile)
        {
            string FileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
            mm.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileName));
        }
        mm.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
        NetworkCred.UserName = "tajpg2013@gmail.com";
        NetworkCred.Password = "*******";
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587;
        smtp.Send(mm);
        lblMessage.Text = "Meassage Sent SucessFully.";
    }
}

Thursday, August 14, 2014

Prevent Copy Paste Url In Asp.net

-------Write Code in Master Page-----------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Request.FilePath.Contains("Default"))
        {
            string strPreviousPage = "";
            if (Request.UrlReferrer != null)
            {
                strPreviousPage = Request.UrlReferrer.Segments[Request.UrlReferrer.Segments.Length - 1];
            }
            if (strPreviousPage == "")
            {
                Response.Redirect("Default.aspx");
            }

        }
    }
}



Disable Browser back Button In Asp.net

-------Write Code in Master Page-----------

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Admin.master.cs" Inherits="Admin" %>

<!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>
     <script type="text/javascript" language="javascript">
         function DisableBackButton() {
             window.history.forward()
         }
         DisableBackButton();
         window.onload = DisableBackButton;
         window.onpageshow = function (evt) { if (evt.persisted) DisableBackButton() }
         window.onunload = function () { void (0) }
 </script>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
       
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>



Monday, August 11, 2014

Autocomplete Input In TextBox Using Asp.net

Discription
Enables users to quickly find and select from a pre-populated list of values as they type, leveraging searching and filtering.

The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are Fruit for Fruit Name, give "a" (for Apple or Grapes) a try

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

<!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 id="Head1" runat ="server">
  <title>jQuery UI Autocomplete</title>
  <link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css"/>
  <script type ="text/javascript" src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script type ="text/javascript"src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
  <link  type="text/css" rel="stylesheet" href="/resources/demos/style.css"/>
  <script type ="text/javascript">
      $(function () {
          var fruitname = [
      "Mango",
      "Apple",
      "Grapes",
      "Banana",
      "BeetRoot",
      "Carrot",
      "Chery",
      "Date",
      "Guava",
      "Kiwi Fruit",
      "Water Melon",
      "Orange",

    ];
          $("#fruit").autocomplete({
              source: fruitname
          });
      });
  </script>
</head>
<body>
    <form id="form1" runat="server">
<div class="div_lang">
    <asp:Label ID="lblname" runat="server" Text="Fruit"></asp:Label>
    <asp:TextBox ID="fruit" runat="server"></asp:TextBox>

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

Saturday, August 09, 2014

JQuery User Interface(UI) Accordion Example

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

<!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>jQuery UI Accordion Example</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script type ="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type ="text/javascript" src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script type="text/javascript">

    $(function () {
        $("#accordion").accordion({
            heightStyle: "fill"
        });
    });
</script>
<style type="text/css">
#accordion-resizer
{
width: 450px;
height: 220px;
font-size:10px;
font-family:Arial;
}
</style>
</head>
<body>
<div id="accordion-resizer">
<div id="accordion">
<h3>HOME</h3>
<div>
<p>Welcome to Aspdotnet.Sunil Kumar
   Welcome to Aspdotnet.Sunil Kumar
</p>
</div>
<h3>ABOUT</h3>
<div>
<p>This Blog offers Asp.net,C#.net,SQL Server,Web Services,WCF,WPF,MVC,
Crystal Reports,AJAX,JavaScript,JQuery,Gridview articles,code examples of asp.net.
</p>
</div>
<h3>CONTACT</h3>
<div>
<p>Welcome to Sunil Kumar
   Welcome to SUNIL Kumar
</p>
<ul>
<li>List item one</li>
<li>List item two</li>
<li>List item three</li>
</ul>    </div>
<h3>ADVERTISE</h3>
<div>
<p>This blog gets updated considering the .net programmers including the newbies as well as the advance developers.
</p>
<p>This blog gets updated considering the .net programmers including the newbies as well as the advance developers.
</p>
</div>
</div>
</div>
</body>
</html>



How to Show Large Image Preview when Hover on Link In Asp.net Using JQuery

Description
Now I will explain how to show large image preview when hover on link or image using JQuery in asp.net.
To implement this concept first create new web application >> Right click on your application >> SelectAdd New Folder and Give name as Image >> Once folder created place some images in folder to show preview of images when hover on link using JQuery in asp.net.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Images_preview.cs" Inherits=" Images_preview " %>

<!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>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        ShowImagePreview();
    });
    // Configuration of the x and y offsets
    function ShowImagePreview() {
        xOffset = -20;
        yOffset = 40;

        $("a.preview").hover(function (e) {
            this.t = this.title;
            this.title = "";
            var c = (this.t != "") ? "<br/>" + this.t : "";
            $("body").append("<p id='preview'><img src='" + this.href + "' alt='Image preview' />" + c + "</p>");
            $("#preview")
     .css("top", (e.pageY - xOffset) + "px")
     .css("left", (e.pageX + yOffset) + "px")
     .fadeIn("slow");
        },

 function () {
    this.title = this.t;
    $("#preview").remove();
});

        $("a.preview").mousemove(function (e) {
            $("#preview")
.css("top", (e.pageY - xOffset) + "px")
.css("left", (e.pageX + yOffset) + "px");
        });
    };

</script>
<style type="text/css">
#preview{
position:absolute;
border:3px solid #ccc;
background:#333;
padding:5px;
display:none;
color:#fff;
box-shadow: 4px 4px 3px rgba(103, 115, 130, 1);
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="Datalist1" runat="server" RepeatColumns="4" CellPadding="5">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" class="preview" ToolTip='<%#Bind("Name") %>' NavigateUrl='<%# Bind("Name", "~/Image/{0}") %>' runat="server">
<asp:Image Width="100" ID="Image1" ImageUrl='<%# Bind("Name", "~/Image/{0}") %>' runat="server" />
</asp:HyperLink>
</ItemTemplate>
<ItemStyle BorderColor="Brown" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Center"
VerticalAlign="Bottom" />
</asp:DataList>
</div>
</form>
</body>
</html>


using System;
using System.IO;
using System.Collections;

public partial class Images_preview: System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }
  
    protected void BindData()
    {
        DirectoryInfo dir = new DirectoryInfo(MapPath("image"));
        FileInfo[] files = dir.GetFiles();
        ArrayList listItems = new ArrayList();
        foreach (FileInfo info in files)
        {
            listItems.Add(info);
        }
        Datalist1.DataSource = listItems;
        Datalist1.DataBind();
    }
}