Live Traffic Feed

Wednesday, May 13, 2015

submit form without passing any data and get all data of form in webmethod

Leave a Comment
script for submiting form to the specifix url.. write SubmitForm.js as follows:

//to call any web service without passing data and get all form data in web service.. Added By Vimal Vataliya
$.fn.SubmitForm = function (url, callback) {
    var form = $(this);
    if (document.getElementById("test_if")) { }//check if this id is already exist
    else {
        var ifram = document.createElement("iframe");//create iframe to store json result
        ifram.id = "test_if";
        ifram.name = "test_if";
        ifram.height = "0px";
        ifram.width = "0px";
        ifram.onload = function () {
            if (form.attr("action")) {//call success function and then distroy iframe and form action url
                callback(document.getElementById("test_if").contentDocument.body.innerText);
                $("#test_if").remove();
                form.removeAttr("action");
            }
        }
        document.body.appendChild(ifram);
        $("#test_if").css({ position: "absolute", top: -1000, left: -1000 });
    }
    $(this).attr("action", url);
    $(this).attr("target", "test_if");
    $(this).submit();
}


then your aspx page like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="jQuery_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="../js/jquery-1.10.2.js" type="text/javascript"></script>
    <script src="SubmitForm.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#btn").click(function () {
                $("#form1").SubmitForm("../WebService.asmx/FillData", test);
            });

        });
        function test(a) {
            var r = $.parseJSON(a);
            alert(r);
        }
    </script>
</head>
<body>
    <form id="form1" enctype="multipart/form-data" method="post">
    <div>
        <input type="text" id="txt" name="txt" /><br />
        <input type="text" id="Text1" name="txt1" /><br />
        <input type="text" id="Text2" name="txt2" /><br />
        <input type="file" id="fu" name="fu" /><br />
        <input type="button" id="btn" value="Submit" />
    </div>
    </form>
</body>
</html>

your WebService.asmx file like this:

using System;
using System.Web;
using System.Web.Services;

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{

    public WebService()
    {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

 
    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }
    [WebMethod]
    public void FillData()
    {
        HttpPostedFile hp = (HttpPostedFile)HttpContext.Current.Request.Files["fu"];
        string a = Convert.ToString(HttpContext.Current.Request.Form["txt"]);
        string b = Convert.ToString(HttpContext.Current.Request.Form["txt1"]);
        string c = Convert.ToString(HttpContext.Current.Request.Form["txt2"]);
        HttpContext.Current.Response.Write(a + "_" + b + "_" + c);
    }

  

}






Read More

Friday, May 1, 2015

call store procedure from function in sql server

Leave a Comment
Function dbo.yourFunctionName
(
yourPara
)
RETURN TABLE
AS
RETURN
(
SELECT * FROM OPENROWSET('SQLNCLI','Server=yourServerName;UID=yourUserName;Pwd=yourPassword;','SET FMTONLY OFF; EXEC yourDataBase.dbo.yourSpName @yourPara') as C
)
Read More