May 21, 2015

[Fixed Solution] : Remove IE's “Clear Button X” From Inputs

This Article Will Give You A Solution To Remove The Internet Explorer's Clear Button "X" On Inputs.

First Will Have A Look On The Issue.
Following HTML Code Lines Will Create A Simple Text Field On The Browser.

<html>
<body>
<input type="text" id="myInput">
</body>
</html>

First Have A Look On The Browsers Like Google Chrome Or Mozilla Firefox.
Type Some Thing In The Text Field.

But Check The Same thing In The Internet Explorer.You Will See The Following Output.
Sometimes This Clear Button Will Annoying You If Your Input Field Has Auto Complete Events.
You Can Add The Follwing CSS Styles To Get Rid Of The Clear Button In The Input Fields In The Internet Explorer.

#myInput::-ms-clear {
    display: none;
}

May 19, 2015

Access C# Method Using JQuery

In This Article I Will Explain You Guys About Accessing Method In C# From JQuery.
My Example Going To Be Very Simple. I Will Have Web Form To Enter A Name & Button Saying "Say Hello".
If You Click The Button Alert Should Come Saying "Hello <Name>".
First Of All Make Sure You Have Simple Idea About ASP.NET Web Sites, C# and JQuery.

Lets Get Into Works.


Create A New "ASP.NET Empty Web Site" & Add A New Web Form For That.

In My Case I have Created As Below.


Then Add A JQuery File To The Web Site.
Then Create The Text Field and Button As Below.

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="jquery.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input type="text" id="txtName" />
            <br/>
            <input type="button" id="btnSayHello" value="Say Hello"/>
        </div>
    </form>
</body>
</html>

Now Lets Create The C# Method.
First Of All Before Sending A Parameter Lets Start With Simple Ajax Call.
Go To "Default.aspx.cs" File & Create Method As Below.

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;

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

    }

    [WebMethod]
    public static string sayHello()
    {
        return "Hello Test";
    }

}

Try To Understand That, Say Hello Is Not Just A Simple Method In C#.It's A Web Method.
Now We Have Created The C# Method.Now What We Have To Do Is Call This Method Using AJAX.

In Order To Do That I'm Creating A Method In Java Script Section.
I Have  Added Script Tag Just Below The Head Tag & I Have Created Method Called "SayHello". Inside This Method I'm Calling The C# Method Using Ajax Call. 

<script>
        function sayHello() {
            $.ajax({
                type: "POST",
                url: "Default.aspx/sayHello",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    alert(response.d);
                },
                failure: function (response) {
                    alert(response.d);
                }
            });
        }

</script>

Run The Project And See.




Now Lets Call The Function With Entered Value.To Do This We Should Call The Ajax Function With JSON Parameter & Change Web Method To Access A Variable.Lets Finish This Off.


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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="jquery.js"></script>
    <script>
        function sayHello() {
            var txtName = $("#txtName").val();
            $.ajax({
                type: "POST",
                url: "Default.aspx/sayHello",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: "{'Name':'" + txtName + "'}",
                success: function (response) {
                    alert(response.d);
                },
                failure: function (response) {
                    alert(response.d);
                }
            });
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input type="text" id="txtName" />
            <br />
            <input type="button" id="btnSayHello" value="Say Hello" onclick="sayHello()" />
        </div>
    </form>
</body>

</html>

Default.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;

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

    }

    [WebMethod]
    public static string sayHello(String Name)
    {
        return "Hello " + Name;
    }
}



May 18, 2015

[Working Solution] Send Email From C# C-Sharp

Let Me Explain You How To Send Emails Through C# Coding.
Using Reference System.Net and System.Net.Mail

//You Will Be Able Understand The Code By Comments
//IF You Face Any Problems Please Contact Me.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Web;
//First You Will Have To Include All These Libraries

namespace PMSWeb.Helpers
{
    public static class EmailHelper
    {  
public static void SendEmail(string fromUser, string toUsers, string ccUsers, string subject, string EmailMessage)
        {
//fromUser - will be the name of your Project . eg. Project Management
//toUsers - List of emails addresses separated by a ,(coma) this will we the To Addresses of the email eg. "test@gmail.com,test@yahoo.com"
//ccUsers - List of emails of CC users separated by a ,(coma)
//subject - subject of the Email Your Sending
//EmailMessage - This will be your email, the body of the email in other words


            string fromUserAddress = "yourEmail@domain";
            // The Email Address Which You Will Be using for Sending the Email.
            string fromUserPassword = "yourEmailPassword";
           //This will be your email addresses password
            string emailHost = "mail.gmail.com";
          //This will be your domains host id eg. mail.gmail.com  this is Gmails Host
            try
            {

                MailMessage message = new MailMessage();
//Create an object from MailMessage
//now (message) object will be an email instance

                string[] ToMuliId = toUsers.Split(',');
                foreach (string ToEMailId in ToMuliId)
                {
                    message.To.Add(new MailAddress(ToEMailId)); //adding multiple Email Addresses
                }

                if (ccUsers != null)
                {
                    string[] CCId = ccUsers.Split(',');

                    foreach (string CCEmail in CCId)
                    {
                        message.CC.Add(new MailAddress(CCEmail));
                       //Adding Multiple CC Email Addresses
                    }
                }
//you could use this if you want BCC also. and you will have to add a parameter for this class
                //string[] bccid = bccUsers.Split(',');

                //foreach (string bccEmailId in bccid)
                //{
                //    message.Bcc.Add(new MailAddress(bccEmailId)); //Adding Multiple BCC email Id
                //}


                message.Subject = subject;
                //assigning the subject received from the parameter to the emails object's subject

                message.IsBodyHtml = true;
                // you can send an HTML String With Styles and Stuff if you keep this true.
//if its just a string email you can keep it false. But you could still send string emails when it is //true

                message.Body = EmailMessage;
               // this will be the place you add the emailMessage to the body of your Email.

                message.From = new MailAddress(fromUserAddress, fromUser);
// sending your email address and your name.

                SmtpClient smtp = new SmtpClient(emailHost, 587);
// your emailHost and and the port , 587 would would work in most cases
             
                //smtp.EnableSsl = true;
//depending on your email host you could make the ssl true or false.


                // Do not send the DefaultCredentials with requests
// Don't know why,  I Also was asked not To.
                smtp.UseDefaultCredentials = false;

                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

  smtp.Credentials = new NetworkCredential(fromUserAddress, fromUserPassword);
//passing your email address and password.

                smtp.Send(message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
                     
        }
    }
}

May 6, 2015

Get Time Zone and UTC From Latitude and Longitude Using JavaScript

This document will demonstrate you to get the time of a location using Google Time API in java script.Simply we need the Latitude and Longitude of location to do that.Hope following code lines will help you.

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
  
$(document).ready(function(){

//Sending A Default Location
var Latitude  = 6.0535185;
var Longitude = 80.22097729999996;
getTimeUsingLatLng(Latitude,Longitude);

function getTimeUsingLatLng(lat,lng){
  var times_Stamp = (Math.round((new Date().getTime())/1000)).toString();
 $.ajax({
  url:"https://maps.googleapis.com/maps/api/timezone/json?location=" + lat + "," + lng + "&timestamp=" + times_Stamp,
  cache: false,
  type: "POST",
  async: false,
 }).done(function(response){

  if(response.timeZoneId != null){
   var Cur_Date = new Date();
  var UTC = Cur_Date.getTime() + (Cur_Date.getTimezoneOffset() * 60000);
  var Loc_Date = new Date(UTC + (1000*response.rawOffset) + (1000*response.dstOffset));
       $("#timeOfLocation").html("Time Of The Location Is " + Loc_Date.toLocaleString());
     }
   });
  } 
});
</script>
</head>
<body>
  <p id = "timeOfLocation"></p>
</body>
</html>


JWT Token Decode Using Jquery

When it come to authentication we use many mechanism. Ones the user authenticated we must keep these details somewhere safe. So we can share...