Popular Posts

Saturday, 21 December 2013

Using Google Co-op's Custom Search Engine

Using Google Co-op's Custom Search Engine



Using google free api you can add a search Engine for your own website ,just need to have a gmail id and follow these steps:

Creating Your Search Engine

The very first step you must take is to visit http://www.google.com/coop/cse.
 (Note that you must have a Google Account. If you don’t have one, Create one. follow the instructions to create your custom search engine.

Where to Host the Custom Search Engine

You have two options on how you can display your search engine to users: Google can host it for you, or you can host the search box and results on your site. For this article, I opted for the latter.
To configure this option:
  1. Return to the Google Co-op Custom Search Engine site’s home page (http://www.google.com/coop/cse).
  2. Click on the My Search Engines link.
  3. When the list of your custom search engines shows up, click on the link that says “Control Panel”.
  4. Next, click on the link that says “Code”.
  5. Select the radio button next to the option that says “Host a search box and search results on your own site…”.
  6. Also, specify the URL of the page on your site where you want the search results to appear.
  7. Finally, after you select the location where you want to display the AdSense ads in your search results, click the Save Changes button.


AFTER REGISTERING THE WEBSITE YOU GET THE CODE JUST PASTE THE CODE IN DIV TAG ON YOUR PAGE WHERE YOU WANT YOUR SEARCH.FOLLOW THE SCREENSHOTS:


1.REGISTER YOUR SITE




2. CREATE YOUR CUSTOM LOOK AND FEEL




3.EXTRACT THE CODE AND PASTE ON YOUR ASPX PAGE



4.DEMO TEST RESULT FOR SEARCH ON YOUR REGISTERED SITE



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

TO CREATE COUNTDOWN TIMER USING AJAX IN ASP.NET

TO CREATE COUNTDOWN TIMER USING AJAX IN ASP.NET


Friends today we will see how to create a countdown timer with the help of ajax.
 

THE DESIGN PAGE:


You need to frst Register the AJAXCONTROLTOOLKIT in your ASPX page .
then follow the simple code:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testpage.aspx.cs" Inherits="testpage" MasterPageFile="~/MasterPages/MasterPage.master"%>

 <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

   
    <style type="text/css">
        .circle
        {
         text-align:center;
        float:left;
        width:60px;
        height:60px;
        background-color:#ffffff;
        border: 1px solid #000000;
        padding:20px 20px 20px 20px;
        -moz-border-radius: 50px;
        -webkit-border-radius: 50px;
        border-radius: 50px;
     
         font-family:Cambria;
         font-size:35px;
        }
        .styletable
        {
          font-family:Cambria;
            font-size:15px;
         font-weight:bold;
        }
     </style>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">

  
    <div id="countdowntimerform" runat="server"><br />
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <br />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
         <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
        </asp:Timer>
        <br />
        <br />
        <table width="260">
        <tr>
         <td><div class="circle"><asp:Label ID="Label1" runat="server"></asp:Label></div></td>
         <td><div class="circle"><asp:Label ID="Label2" runat="server"></asp:Label></div></td>
         <td><div class="circle"><asp:Label ID="Label3" runat="server"></asp:Label></div></td>
         <td><div class="circle"><asp:Label ID="Label4" runat="server"></asp:Label></div></td>
        </tr>
        <tr align="center"><td><b>DAYS</b></td><td><b>HOURS</b></td><td><b>MIN</b></td><td><b>SEC</b></td></tr></table
        </ContentTemplate>
        </asp:UpdatePanel>
         </div>
   </asp:Content>


THE CODE BEHIND:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;

public partial class testpage : System.Web.UI.Page
{
    static DateTime setdt;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { 
            
        
            DateTime time = DateTime.Now;              // Use current time
            string format = "d mm yyyy HH:mm:ss ";    // Use this format
            Console.WriteLine(time.ToString(format));  // Write to console


          DateTime  date1 = (time.AddMinutes(3));  
//HERE I HAVE ADDED THE TIMER TO 3 MINUTES FROM THE CURRENT TIME.SO THE //COUNTDOWN WILLSTARTS WITH 3 MINUTES REMAINING.
  
        Session["addedtime"] = date1;
          Timer1.Enabled = true;
        }
    }


    protected void Timer1_Tick(object sender, EventArgs e)
    {
        DateTime dt = DateTime.Now;
        TimeSpan differ;
        
      //   System.DateTime date1 = new System.DateTime();
        DateTime date1 = (DateTime)Session["addedtime"];
        differ = date1.Subtract(dt);
        double t = differ.TotalSeconds;

        if (t > 0)
        {
            double yr, mnth, dy, h, m, s;
            dy = differ.Days;
            h = differ.Hours;
            m = differ.Minutes;
            s = differ.Seconds;
            Label1.Text = dy.ToString();// +" Days " + h + " Hours " + m + " Minutes " + s + " Seconds left for celebration";
            Label2.Text = h.ToString();
            Label3.Text = m.ToString();
            Label4.Text = s.ToString();
        }
        else
        {
            Timer1.Enabled = false;
//and perform your other logic here
        }
    }
   
}

 

SENDING SMS THROUGH ASP.NET PROGRAMM

SENDING SMS OTP(ONE TIME  PASSWORD) TO USER MOBILE NO.


Hello friends this post explains the way where you can send the sms to any user mobile ,where i am sending or applying the concept on OTP to be send to registered user for his authentication.

In general, there are two ways to send SMS messages from a computer / PC to a mobile phone:
  1. Connect a mobile phone or GSM/GPRS modem to a computer / PC. Then use the computer / PC and AT commands to instruct the mobile phone or GSM/GPRS modem to send SMS messages.
  2. Connect the computer / PC to the SMS center (SMSC) or SMS gateway of a wireless carrier or SMS service provider. Then send SMS messages using a protocol / interface supported by the SMSC or SMS gateway.
HERE WE WILL DISCUSS THE SECOND WAY.TO REFER THE FIRST WAY I FOUND AN ARTICLE  ON CODE PROJECT:

THE DESIGN PAGE:

The design page will consists of user register form where he fills up the data and wait to recieve the sms code and need to enter the OTP and validation will be done.


THE CODE BEHIND:
TO SEND SMS:


this is the simple function created to send the OTP  to user mobile no:

   protected Int32 sendonetimepass(string username, string mobileno, string emailid)
    {
        try
        {
         

            Random _r = new Random();  //random number function to generate OTP

            int n = _r.Next(10000);


            System.IO.Stream Str = null;
            System.IO.StreamReader srRead = null;  //object of streamReader
            string PageContent = null;
            string strTmpContact = string.Empty;
            string message = "Dear User " + username + " ,Your One Time Password(OTP) is " + n + " ,please enter to confirm your identity/authenticity";
            if (n > 0)
            {
                string url = ("http://www.URPROVIDER.in/SendTestSMS/SendTESTMsg.php?uname=URREGISTERDNAME&pass=URPASSWORD&send=URREGISTRATIONNO&dest=91" + mobileno + "&msg=TITLE_OF_MESSAGE ") + message + "";


// the string Url consistis of  the the url string provided to u by the SERVICE PROVIDER TO SEND SMS.
// You can send SMS using ASP.net web application. First you hunt for good SMS provider API.    //API should be capable of sending long messages more than 160 characters.    //It works with http Get Method. Below is the code snippet to deal with an API.                


 System.Net.WebRequest req = System.Net.WebRequest.Create(url);
                System.Net.WebResponse resp = req.GetResponse();
                Str = resp.GetResponseStream();
                srRead = new System.IO.StreamReader(Str);
                // read all the text
                PageContent = srRead.ReadToEnd();

            }
            if ((srRead != null) & (Str != null))
            {
                srRead.Close();
                Str.Close();
            }
            return n;
        }

        catch (Exception ex)
        {
            return 0;

        }

    }



TO VALIDATE THE SMS ENTERED BY USER:

Once the sms is send successfully then you can save the sms of the user with his name and others details in the DB and can check when he enters.LIKE:



string query = "insert into userotpdetails values('" + txtUserName.Text + "','" + txtUserID.Text + "','" + txtPassword.Text + "','" + txtMobile.Text + "','" + txtEmailID.Text + "'," + otp + ",'" + currentdatetime + "')";
                DBAccess obj1 = new DBAccess();
                string result = obj1.OracleExecute(query);
                if (result == "Success")
                {
SYSTEM.OUT.PRINTLN("DETAILS SUBMMITED SUCCESFULLY");
               }

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