Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
Hello sir/madam


I am designing my own Email System like Gmail. In this I want to use word prediction technique in Compose mail TextBox.

I mean when Someone type something in compose mail textbox ,it should automatically retrieve values from database.

That's fine,, With PHYSICAL KEYBOARD it is happening successfully.  I have used Jquery Autocomplete textbox technique.

MAIN PROBLEM IS:-

When I have also used google virtual keyboard facility in my project. When I type something from virtual keyboard Autocomplete textbox does not work,It does not retrieve values from database, but when i use physical keyboard it works.

WHAT SHOULD I ADD IN MY CODE TO WORK IT WITH VIRTUAL KEYBOARD SUCCESFULLY?????????

MY CODE IS:-

Default.aspx:-

<%@ 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>

    <link href="css/ui-lightness/jquery-ui-1.8.21.custom.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>

<script type="text/javascript">
   $(document).ready(function () {
       SearchText();
   });



   function SearchText() {
       $("#TextBox1").autocomplete({
           source: function (request, response) {
               $.ajax({
                   type: "POST",
                   contentType: "application/json; charset=utf-8",
                   url: "Default.aspx/GetAutoCompleteData",
                   data: "{'username':'" + extractLast(request.term) + "'}",
                   dataType: "json",
                   success: function (data) {
                       response(data.d);
                   },
                   error: function (result) {
                       alert("Error");
                   }
               });
           },
           focus: function () {
               // prevent value inserted on focus
               return false;
           },
           select: function (event, ui) {
               var terms = split(this.value);
               // remove the current input
               terms.pop();
               // add the selected item
               terms.push(ui.item.value);
               // add placeholder to get the comma-and-space at the end
               terms.push("");
               this.value = terms.join(" ");
               return false;
           }
       });



       $("#TextBox1").bind("keydown", function (event) {
           if (event.keyCode === $.ui.keyCode.TAB &&
$(this).data("autocomplete").menu.active) {
               event.preventDefault();
           }
       })
       function split(val) {
           return val.split(" ");
       }
       function extractLast(term) {
           return split(term).pop();
       }
   }
</script>









    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>

    <script src="//www.google.com/jsapi?key=AIzaSyA5m1Nc8ws2BbmPRwKu5gFradvD_hgq6G0" type="text/javascript"></script>
    <script type="text/javascript">
        /*
        *  How to setup a textarea that allows typing with a Russian Virtual Keyboard.
        */

        google.load("elements", "1", { packages: "keyboard" });

        function onLoad() {


            var kbd = new google.elements.keyboard.Keyboard(
          [google.elements.keyboard.LayoutCode.HINDI],
          ['TextBox1']);






        }

        google.setOnLoadCallback(onLoad);

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="demo">
<div class="ui-widget">
        <asp:TextBox ID="TextBox1" runat="server" Height="39px" Width="314px"  ></asp:TextBox>
    </div>
    </div>
    </form>
</body>
</html>

---------------------------------------------------------------------

Default.aspx.cs:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Services;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
     [WebMethod]

    public static List<string> GetAutoCompleteData(string username)
    {
        List<string> result = new List<string>();
        using (SqlConnection con = new SqlConnection("Data Source=GAURAV;Initial Catalog=emailproject;Integrated Security=True"))
        {
            using (SqlCommand cmd = new SqlCommand("select DISTINCT hindiname from hindiword where hindiname LIKE '%'+@SearchText+'%'", con))
            {
                con.Open();
                cmd.Parameters.AddWithValue("@SearchText", username);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    result.Add(dr["hindiname"].ToString());
                }
                return result;
            }
        }
    }
}
Thank You Very Much....
Waiting for your favorable response...............
Regards
Gaurav Bhardwaj
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900