Share Blog

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




Friday, August 08, 2014

How To Find Name Of The Day from Date In Asp.net

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

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime dt = new DateTime(2014, 8, 8);
       Response.Write(dt.ToString("dddddddddd"));
    }
  
}


How To Evaluate Mathematical/Arithmatic Expression string Expression 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>
    <fieldset style=" width:300px">
    <legend>Evaluate String Arithmetic Expression</legend>  
        <asp:TextBox ID="TxtEquation" runat="server"></asp:TextBox>
        <asp:Button ID="BtnCalculate" runat="server" Text="Calculate"
            onclick="btnCalculate_Click" />
              
        <asp:Button ID="btnReset" runat="server" Text="Reset"
            onclick="btnReset_Click" />  
        <br />
        <asp:Label ID="lblResult" runat="server" Text=""></asp:Label>
        </fieldset>
    </div>
    </form>
</body>

</html>

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

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
     
    }
    private object EvaluateExpression(string Equation)
    {
        DataTable dt = new DataTable();
        var Result = dt.Compute(Equation, string.Empty);
        return Result;
    }
 
    protected void btnReset_Click(object sender, EventArgs e)
    {
        TxtEquation.Text = "";
        TxtEquation.Focus();
    }
    protected void btnCalculate_Click(object sender, EventArgs e)
    {
        try
        {
            var Result = Convert.ToString(EvaluateExpression(TxtEquation.Text.Trim()));
            lblResult.Text = " Your Result" + Result;
            lblResult.ForeColor = Color.Blue;
        }
        catch (Exception ex)
        {
            lblResult.Text = "Ooops!" + ex.Message.ToString();
            lblResult.ForeColor = Color.Red;
        }
    }
}