Monday, October 7, 2013

JQuery UI autocomplete textbox with database in asp.net

WebForm1.aspx:-
-------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            SearchText();
        });
        function SearchText() {
            $("#txtSearch").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "WebForm2.aspx/GetAutoCompleteData",
                        data: "{'username':'" + $("#txtSearch").val() + "'}",
                        dataType: "json",
                        success: function (data) {
                            response(data.d);
                        },
                        error: function (result) {
                            alert("Error");
                        }
                    });
                },
                select: function (event, ui) {
                    fillDdl(ui.item.value);
                }
            });
            function fillDdl(value) {
                $.ajax({
                    url: "WebForm2.aspx?name=" + value,
                    async: true,
                    data: {
                    },
                    success: function (data) {
                        var n = data.split(",");
                        for (var i = 0; i < n.length; i++) {
                            var newOption = $('<option value="' + n[i] + '">' + n[i] + '</option>');
                            $('#ddl').append(newOption);
                        }
                    },
                    error: function (data) {
                        alert(data);
                    }
                });
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <label for="lblSearch">Search: </label>           
            <input id="txtSearch" />
            <select id="ddl">
                <option>Select</option>
            </select>
        </div>
    </form>
</body>
</html>


WebForm2.aspx.cs:-
-----------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string strName = Request.QueryString["name"];
            if (strName != "" && strName != null)
            {
                var strResult1 = "a,b,c,d";
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Write(strResult1);
                HttpContext.Current.Response.End();
            }
        }
        [WebMethod]
        public static List<string> GetAutoCompleteData(string username)
        {
            List<string> result = new List<string>();
            result.Add("one");
            result.Add("two");
            result.Add("three");
            return result;
        }

        //[WebMethod]
        //public static List<string> GetAutoCompleteData(string username)
        //{
        //    List<string> result = new List<string>();
        //    using (SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB"))
        //    {
        //        using (SqlCommand cmd = new SqlCommand("select DISTINCT UserName from UserInformation where UserName LIKE '%'+@SearchText+'%'", con))
        //        {
        //            con.Open();
        //            cmd.Parameters.AddWithValue("@SearchText", username);
        //            SqlDataReader dr = cmd.ExecuteReader();
        //            while (dr.Read())
        //            {
        //                result.Add(dr["UserName"].ToString());
        //            }
        //            return result;
        //        }
        //    }
        //}
    }

}
---------------------------------------------------------------------------
Other Example:-
------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication2.WebForm3" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script type="text/javascript">
        $(function () {
            var x = [
            { label: 'apple', value: 'Delicious' },
            { label: 'kiwi', value: 'Yummy' },
            { label: 'kiwiooo', value: 'aaa' },
            { label: 'lemon', value: 'Sour' }
            ];
            $("#fruit").autocomplete({
                source: x,
                focus: function () { return false; }
            })
            .on('autocompleteresponse autocompleteselect', function (e, ui) {
                var t = $(this),
                    details = $('#details'),
                    label = (e.type == 'autocompleteresponse' ? ui.content[0].label : ui.item.label),
                    value = (e.type == 'autocompleteresponse' ? ui.content[0].value : ui.item.value);
                t.val(label);
                details.val(value);
                return false;
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input id='fruit' name='fruit' type='text'>
            <input id='details' name='details' type='text'>
        </div>
    </form>
</body>
</html>


Thank You.

Sunday, October 6, 2013

Issue: SqlCommand: 'proc_FetchDocForHttpGet' CommandType: StoredProcedure CommandTimeout: 0

After install SharePoint 2013 following issue comming.....
SqlCommand: 'proc_FetchDocForHttpGet'     CommandType: StoredProcedure CommandTimeout: 0     Parameter: '@RETURN_VALUE' Type: Int Size: 0 Direction: ReturnValue Value: ''     Parameter: '@DocSiteId' Type: UniqueIdentifier Size: 0 Direction: Input Value: 'cf3d77dd-9862-4b81-af02-ab7bae85db2e'     Parameter: '@DocDirName' Type: NVarChar Size: 4000 Direction: Input Value: ''     Parameter: '@DocLeafName' Type: NVarChar Size: 4000 Direction: Input Value: 'default.aspx'     Parameter: '@LooksLikeAttachmentFile' Type: Bit Size: 0 Direction: Input Value: 'False'     Parameter: '@IfModifiedSince' Type: DateTime Size: 0 Direction: Input Value: ''     Parameter: '@FetchType' Type: Int Size: 0 Direction: Input Value: '0'     Parameter: '@ValidationType' Type: Int Size: 0 Direction: Input Value: '0'     Parameter: '@ClientVersion' Type: Int Size: 0 Direction: Input Value: ''     Parameter: '@ClientId' Type: UniqueIdentifier Size: 0 Direction: Input Value: ''     Parameter: '@PageView' Type: TinyInt Size: 1 Direction: Input Value: '1'     Parameter: '@FetchBuildDependencySet' Type: Bit Size: 0 Direction: Input Value: 'True'     Parameter: '@SystemId' Type: VarBinary Size: 8000 Direction: Input     Parameter: '@AppPrincipalName' Type: NVarChar Size: 256 Direction: Input Value: ''     Parameter: '@IsHostHeaderAppPrincipalName' Type: Bit Size: 0 Direction: Input Value: ''     Parameter: '@CurrentVirusVendorID' Type: Int Size: 0 Direction: Input Value: ''     Parameter: '@PrefetchListScope' Type: Bit Size: 0 Direction: Input Value: 'True'     Parameter: '@ChunkSize' Type: Int Size: 0 Direction: Input Value: '64320'     Parameter: '@DGCacheVersion' Type: BigInt Size: 0 Direction: Input Value: '2'     Parameter: '@MaxCheckinLevel' Type: TinyInt Size: 1 Direction: Input Value: '1'     Parameter: '@HonorLevel' Type: Bit Size: 0 Direction: Input Value: 'False'     Parameter: '@CurrentFolderUrl' Type: NVarChar Size: 4000 Direction: Input Value: ''     Parameter: '@ThresholdRowCount' Type: Int Size: 0 Direction: Input Value: '5000'     Parameter: '@StreamPartition' Type: TinyInt Size: 1 Direction: Input Value: '0'     Parameter: '@Level' Type: TinyInt Size: 0 Direction: Output Value: ''     Parameter: '@FetchStreamIfNeeded' Type: Bit Size: 0 Direction: Input Value: 'True'     Parameter: '@RequestGuid' Type: UniqueIdentifier Size: 0 Direction: Input Value: '2c134a9c-1823-c09c-7ae3-cd3de10c8416'

resolution:-
i gave db_owner right to my service account user. after refresh my central admin it is opened.
(this is permission related issue in database).
Thank You.

Thursday, October 3, 2013

Deployment conflics were detected. Would you like Visual Studio to resolve them for you?


Each time I deploy my solution my list gets deleted:
SP2010 Deployment: Beware of "Deployment Conflict Resolution Behavior"



Thank You.

Featured Post

Automating Azure DevOps Task Tracking: A Complete PowerShell Solution

Automating Azure DevOps Task Tracking: A Complete PowerShell Solution param ( [ Parameter ( Mandatory = $false )] [ Alias ( 'Fr...

Popular posts