Passing the value from code behind to jquery ( using JSON )

 Passing the value from code behind to jquery ( using JSON )

.ASPX File

<asp:Button ID=”btnSubmit” runat=”server” Text=”Submit” OnClick=”btnSubmit_Click” OnClientClick=”return CheckEmpID();” />

Script File

function CheckEmpID()
{
var EmrID = document.getElementById(“txtEmpId”).value;
if (EmpID == “Enter New EMPID”) return false;
$.ajax({
type: “post”,
url: “EmpWelcomeScreen.aspx/EmpDetails”,
contentType: “application/json; charset=utf-8”,
data: ‘{“EmpId”:”‘ + EmpID + ‘”}’,
dataType: “json”,
success: function (msg) {
if (msg.d[0] == “0”)
document.location = msg.d[1];
else if (msg.d[0] == “1”)
document.getElementById(“lblEmpId”).style.display = “”;
else if (msg.d[0] == “2”)
document.getElementById(“lblIssue”).value = d[1];
},
error: function (data) { }
} );

return false;
}

Code-Behind

[System.Web.Services.WebMethod()]
public static string[] EmpDetails(string EmpId)
{
string[] ReturnString = new string[2];
string EmpName = txtEmpName.Text.ToString()
try
{
if (EmpId.Length > 0)
{
if (EmpName != null)
{
ReturnString[0]=”0″;
ReturnString[1] = “EmpInfoSummary.aspx?Empid=” + EmpId;
}
else
{
ReturnString[0] = “1”;
ReturnString[1] = “Plaese Check The EMPID “;
}
}
}
catch (Exception ex)
{

}
return ReturnString;
}