Wednesday, 27 June 2012

how to send mail in webmatrix

Sending E-mail

Sending e-mail from an ASP.NET web site was already quite easy, but by adding some Helper methods things are now easier than ever:
var customerName = Request["customerName"];     
var customerRequest = Request["customerRequest"]; 

// Initialize Mail helper
Mail.SmtpServer = "your SMTP host";
Mail.SmtpPort = 587;
Mail.EnableSsl = true;
Mail.UserName = "your user name here";
Mail.From = "your email address here";
Mail.Password = "your accound password";

// Send email
Mail.Send(to: "target email address here", subject: "Help request from - " + 
       customerName, body: customerRequest
);  

how to file upload in webmatrix

Uploading files looks quite similar to the FileUpload control and the File class in .NET. You can define an upload control in the page like this:
@FileUpload.GetHtml
(
  initialNumberOfFiles:1, 
  allowMoreFilesToBeAdded:false, 
  includeFormTag:true, 
  uploadText:"Upload")
  @if (IsPost) {
    <span>File uploaded!</span><br/>
}     
To save the file, you can use code like this:
@{  
  var fileName = "";
  if (IsPost) {
    var fileSavePath = "";
    var uploadedFile = Request.Files[0];
    fileName = Path.GetFileName(uploadedFile.FileName);
    fileSavePath = Server.MapPath("~/App_Data/UploadedFiles/" + fileName);
    uploadedFile.SaveAs(fileSavePath);
  } 
}
Notice how properties such as initialNumberOfFiles and allowMoreFilesToBeAdded make it easy to change the client side behavior of the upload page. Set allowMoreFilesToBeAdded to true and the user gets an Add button to upload multiple files at once, shown in figure 7:


Besides uploading files, WebMatrix also makes it easy to work with images. For example, you can scale and flip images and there is built-in support for adding watermarks, something that previously required third party controls or a fair bit of custom code.

Tuesday, 26 June 2012

how to open new window through response.redirec

 Response.Redirect("BookSearch.aspx?Card=" + TxtSearch.Text, "_blank", "menubar=0,width=700,height=500,status=yes,toolbar=no,location=no,scrollbars=yes,resizable=no,titlebar=no");

Friday, 15 June 2012

Paging in aps.net using jquery and json

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

<!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">
    <script src="JScript.js" type="text/javascript"></script>
    <script src="JScript2.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        var p = 2;
        var k = 0;
        function pp(s) {
        var m=(parseInt(s)- parseInt(1))*parseInt(p);
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "WebService.asmx/yy",
                data: "{s:"+m+",t:"+p+"}",
                dataType: "json",
                async: false,
                success: function (data) {
                    k = data.d.length
                    $('#gv').html('');
                    $('#gv').append("<tr><th>EID</th><th>NAME</th></tr>");
                    for (var i = 0; i < p; i++)
                        $('#gv').append("<tr><th>" + data.d[i].DID + "</th><th>" + data.d[i].DNAME + "</th></tr>");
                }

            });
        }
        $(document).ready
    (
    function () {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "WebService.asmx/x",
            data: "",
            dataType: "json",
            async: false,
            success: function (data) {
                k = data.d.length
                $('#gv').html('');
                $('#gv').append("<tr><th>EID</th><th>NAME</th></tr>");
                for (var i = 0; i < p; i++)
                    $('#gv').append("<tr><th>" + data.d[i].DID + "</th><th>" + data.d[i].DNAME + "</th></tr>");
                var n = Math.ceil(parseInt(k) / parseInt(p));
                $('#gv1').html('');
                $('#gv1').append("<tr><td colspan='2'>");
                for (var j = 1; j <= n; j++)
                    $('#gv1').append("<a style='text-decoration:none' href='#' onclick='pp(" + j + ")'>" + j + "</a> ");
                $('#gv1').append("</td></tr>");
            }

        });


    }
    )
    </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table align="center" cellpadding=0 cellspacing=0 >
    <tr><td colspan="2">
    <table id="gv" width="100%" align="center" border=1 cellpadding=0 cellspacing=0>
    </table>
    </td></tr>
    <tr><td colspan="2">
    <table width="100%" id="gv1" align="center" border=1 cellpadding=0 cellspacing=0>
    </table>
    </td></tr>
    </table>
   
    </div>
    </form>
</body>
</html>

The page looks like :










Web service Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

    DataClassesDataContext o = new DataClassesDataContext();
    public WebService ()
    {

       
    }
    [WebMethod]
    public List<EMP> x()
    {
        return o.EMPs.ToList();
    }
    [WebMethod]
    public List<EMP> yy(int s,int t)
    {
        var m = (from x in o.EMPs select x).Skip(s).Take(t).ToList();
        return m;
    }
    [WebMethod]
      
}


Thursday, 14 June 2012

Example of list box in asp.net using jquery and json

<%@ 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>
    <script src="JScript.js" type="text/javascript"></script>
    <script src="JScript2.js" type="text/javascript"></script>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">
        $(document).ready
       (
            function () {
                $('#btn3').click
            (
                function () {
                $('#ddl option').remove()
                $('#ddl').append("<option value=0>------Select------</option>")
                $('#ddl1 option').each(function (i, j) {
                    $('#ddl').append("<option value='" + $(j).val() + "'>" + $(j).text() + "</option>")
                });
                }
            )
                $('#btn2').click(
                function () {
                    $('#ddl option').remove()
                    $('#ddl').append("<option value=0>------Select------</option>")
                    $('#ddl1 option:selected').each(function (i, j) {
                        $('#ddl').append("<option value='" + $(j).val() + "'>" + $(j).text() + "</option>")
                    });
                }
                )
                $('#btn1').click(
                function () {
                    $('#ddl1 option').remove()
                    $('#ddl1').append("<option value=0>------Select------</option>")
                    $('#ddl option:selected').each(function (i, j) {
                        $('#ddl1').append("<option value='" + $(j).val() + "'>" + $(j).text() + "</option>")
                    })
                }

            )
                $('#btn').click(
            function () {
                $('#ddl1 option').remove()
                $('#ddl option').each(function (i, j) {
                    $('#ddl1').append("<option value='" + $(j).val() + "'>" + $(j).text() + "</option>")
                }
              )
            }
            )
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "WebService.asmx/x",
                    data: "",
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        $('#ddl').append("<option value=0>------Select------</option>");
                        for (var i = 0; i < data.d.length; i++) {
                            $('#ddl').append("<option value=" + data.d[i].DID + ">" + data.d[i].DNAME + "</option>");

                        }

                    }
                });



            }
       )
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table align="center">
            <tr>
                <td>
                    <select id="ddl" name="ddl" size="2" multiple="multiple">
                    </select>
                </td>
                <td>
                    <input type="button" id="btn" name="btn" value=">>" style="width: 30px" /><br />
                    <input type="button" id="btn1" name="btn1" value=">" style="width: 30px" /><br />
                    <input type="button" id="btn2" name="btn2" value="<" style="width: 30px" /><br />
                    <input type="button" id="btn3" name="btn3" value="<<" style="width: 30px" />
                </td>
                <td>
                    <select id="ddl1" name="ddl1" multiple="multiple" size="2">
                    </select>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
The page looks like



Tuesday, 12 June 2012

cascading list box in asp.net using jquery,json and linq

<%@ 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>
    <script src="JScript.js" type="text/javascript"></script>
    <script src="JScript2.js" type="text/javascript"></script>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">
        $(document).ready
       (
            function () {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "WebService.asmx/x",
                    data: "",
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        $('#ddl').append("<option value=0>------Select------</option>");
                        for (var i = 0; i < data.d.length; i++) {
                            $('#ddl').append("<option value=" + data.d[i].DID + ">" + data.d[i].DNAME + "</option>");

                        }

                    }
                });

                $('#ddl').change
             (
             function () {
                 $.ajax({
                     type: "POST",
                     contentType: "application/json; charset=utf-8",
                     url: "WebService.asmx/y",
                     data: "{a:" +  $('#ddl option:selected').val() + "}",
                     dataType: "json",
                     async: false,
                     success: function (data) {
                         $('#ddl1 option').remove()
                         $('#ddl1').append("<option value=0>------Select------</option>");
                         for (var i = 0; i < data.d.length; i++) {
                             $('#ddl1').append("<option value=" + data.d[i].EID + ">" + data.d[i].NAME + "</option>");

                         }

                     }
                 });
             }
             )
            }
       )
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <select id="ddl" name="ddl" size="2" multiple="multiple">
    </select><br />
    <select id="ddl1" name="ddl1"  multiple="multiple" size="2"></select><br />
    <input type="button" value="Save"  />
    </div>
    </form>
</body>
</html>

Page looks like:

web service Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

    DataClassesDataContext o = new DataClassesDataContext();
    public WebService ()
    {

       
    }
    [WebMethod]
    public List<EMP> x()
    {
        return o.EMPs.ToList();
    }
    [WebMethod]
    public List<EMP1> y(int a)
    {
        var m = from x in o.EMP1s where x.DID == a select x;
        return m.ToList();
    }

   
}


Monday, 11 June 2012

how to insert,update,delete and view in MVC using json and jquery

view code:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication46.Models.EMP>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  <style type="text/css">
        #popupBoxClose
        {
            font-size: 10px;
            line-height: 15px;
            right: 5px;
            top: 5px;
            position: absolute;
            color: #6fa5e2;
            font-weight: 500;
        }
        #popup_box
        {
            display: none; /* Hide the DIV */
            position: fixed;
            _position: absolute; /* hack for internet explorer 6 */
            height: 300px;
            width: 600px;
            background: #FFFFFF;
            left: 300px;
            top: 150px;
            z-index: 100; /* Layering ( on-top of others), if you have lots of layers: I just maximized, you can change it yourself */
            margin-left: 15px; /* additional features, can be omitted */
            border: 2px solid #999999;
            padding: 15px;
            font-size: 15px;
            -moz-box-shadow: 0 0 5px #ff0000;
            -webkit-box-shadow: 0 0 5px #ff0000;
        }
    </style>
    <script src="../../Scripts/JScript.js" type="text/javascript"></script>
    <script src="../../Scripts/JScript2.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        function y(s) {
            $.getJSON('/Home/m', { a: s }, function (data) {
                $("#gv").html("");
                $("#gv").append("<tr><th>DELETE</th><th>UPDATE</th><th>EID</th><th>NAME</th></tr>");
                for (var i = 0; i < data.length; i++) {
                    $("#gv").append("<tr><td><a href='#' style='text-decoration: none' onclick='y(" + data[i].EID + ")'>Delete</a></td><td><a href='#' style='text-decoration: none' onclick='x(" + data[i].EID + ")'>Edit</a></td><td>" + data[i].EID + "</td><td>" + data[i].NAME + "</td></tr>");

                }
            });
        }
        function x(s) {
            $.getJSON('/Home/y', { a: s }, function (data)
             {
                $('#tb').attr("value", data[0].EID);
                $('#tb1').attr("value", data[0].NAME);
            });
            $('#popup_box').slideDown("slow");
        }
        $(document).ready(
        function () {
            $.getJSON('/Home/n', '', function (data) {

                $("#gv").html("");
                $("#gv").append("<tr><th>DELETE</th><th>UPDATE</th><th>EID</th><th>NAME</th></tr>");
                for (var i = 0; i < data.length; i++) {

                    $("#gv").append("<tr><td><a href='#' style='text-decoration: none' onclick='y(" + data[i].EID + ")'>Delete</a></td><td><a href='#' style='text-decoration: none' onclick='x(" + data[i].EID + ")'>Edit</a></td><td>" + data[i].EID + "</td><td>" + data[i].NAME + "</td></tr>");

                }
            });
            $('#btn1').click(
        function () {
            $.getJSON('/Home/z', { a: $('#tb').val(), b: $('#tb1').val() }, function (data) {
                $("#gv").html("");
                $("#gv").append("<tr><th>DELETE</th><th>UPDATE</th><th>EID</th><th>NAME</th></tr>");
                for (var i = 0; i < data.length; i++) {
                    $("#gv").append("<tr><td><a href='#' style='text-decoration: none' onclick='y(" + data[i].EID + ")'>Delete</a></td><td><a href='#' style='text-decoration: none' onclick='x(" + data[i].EID + ")'>Edit</a></td><td>" + data[i].EID + "</td><td>" + data[i].NAME + "</td></tr>");

                }
            });
            $('#popup_box').slideUp("slow");
        }
        )
            JqueryAction();
            function ShowPopUp() {
                $('#popup_box').slideDown("slow");
            }
            function JqueryAction() {

                $('#popupBoxClose').click(
             function () {
                 $('#popup_box').slideUp("slow");
             }
            );
            }
            $('#btn').click
        (
        function () {
            $.getJSON('/Home/x', { a: $('#EID').val(), b: $('#NAME').val() }, function (data) {

                $("#gv").html("");
                $("#gv").append("<tr><th>DELETE</th><th>UPDATE</th><th>EID</th><th>NAME</th></tr>");
                for (var i = 0; i < data.length; i++) {

                    $("#gv").append("<tr><td><a href='#' style='text-decoration: none' onclick='y(" + data[i].EID + ")'>Delete</a></td><td><a href='#' style='text-decoration: none' onclick='x(" + data[i].EID + ")'>Edit</a></td><td>" + data[i].EID + "</td><td>" + data[i].NAME + "</td></tr>");

                }
            });
        }

        )
        }
        )
    </script>
    <%using (Html.BeginForm())
      { %>
      <form id="f">
      <table align="center">
      <tr><td>EID</td><td><%=Html.TextBoxFor(Model=>Model.EID) %></td></tr>
      <tr><td>NAME</td><td><%=Html.TextBoxFor(Model=>Model.NAME) %></td></tr>
      <tr><td>&nbsp;</td><td><input type="button" value="Save" id="btn" name="btn" /></td></tr>
      <tr><td colspan="2">
      <table id="gv" width="100%" border="1" cellpadding="0" cellspacing="0">
      </table>
      </td></tr>
      </table>
       <div id="popup_box">
            <table align="center">
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        <div id="popupBoxClose">
                            <a href="#" style="text-decoration: none">Close</a></div>
                    </td>
                </tr>
                <tr>
                    <td>
                        EID
                    </td>
                    <td>
                       <input type="text" id="tb" name="tb" />
                    </td>
                </tr>
                <tr>
                    <td>
                        NAME
                    </td>
                    <td>
                         <input type="text" id="tb1" name="tb1" />
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        <input type="button" id="btn1" name="btn1" value="Update" />
                    </td>
                </tr>
            </table>
        </div>
            </form>
    <%} %>
</asp:Content>
Page looks like:


Controller code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication46.Models;

namespace MvcApplication46.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        DataClasses1DataContext o = new DataClasses1DataContext();
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }
        public JsonResult x(int a, string b)
        {
            EMP p = new EMP();
            p.EID = a;
            p.NAME = b;
            o.EMPs.InsertOnSubmit(p);
            o.SubmitChanges();
            return Json(o.EMPs.ToList(), JsonRequestBehavior.AllowGet);
        }
        public JsonResult z(int a, string b)
        {
            var m = (from x in o.EMPs where x.EID == a select x).First();
            m.NAME = b;
            o.SubmitChanges();
            return Json(o.EMPs.ToList(), JsonRequestBehavior.AllowGet);
        }
        public JsonResult m(int a)
        {
            var m = (from x in o.EMPs where x.EID == a select x).First();
            o.EMPs.DeleteOnSubmit(m);
            o.SubmitChanges();
            return Json(o.EMPs.ToList(), JsonRequestBehavior.AllowGet);
        }
        public JsonResult y(int a)
        {
            var m=(from x in o.EMPs where x.EID==a select x).ToList();
            return Json(m, JsonRequestBehavior.AllowGet);
        }
        public JsonResult n()
        {
            return Json(o.EMPs.ToList(), JsonRequestBehavior.AllowGet);
        }
    }
}