<script type = "text/javascript" language="javascript">
var RedirectPath = '<%= "http://" + Request.ServerVariables["HTTP_HOST"].ToString() + Request.ApplicationPath+"/Ajax/checkuser.aspx" %>';
function GetName(source, args) {
var current_path = window.location;
if(current_path.toString().substr(0,5) == "https")
{
RedirectPath = '<%= "https://" + Request.ServerVariables["HTTP_HOST"].ToString() + Request.ApplicationPath+"/Ajax/checkuser.aspx" %>';
}
hdnrefuserexit = document.getElementById("<%=hdnrefuserexit.ClientID %>");
txtReferredBy = document.getElementById("<%=txtReferralID.ClientID %>");
lableMessage = document.getElementById("<%=lblError1.ClientID %>");
referralID = txtReferredBy.value;
if(referralID!="")
{
$.ajax({
type: "POST",
url: RedirectPath,
data: "q=" + referralID+"&t=referral" ,
success: function(response) {
if(response !="failed")
{
if(response=="false")
{
lableMessage.innerHTML = "Referral User does not exist";
lableMessage.style.color = "Red";
hdnrefuserexit.value = "false";
txtReferredBy.focus();
args.IsValid = false;
}
else
{
lableMessage.innerHTML = response.toString();
lableMessage.style.color = "Green";
hdnrefuserexit.value = "true";
args.IsValid = true;
}
}
else if(response =="failed")
{
lableMessage.innerHTML = "Referral User does not exist";
lableMessage.style.color = "Red";
txtReferredBy.focus();
hdnrefuserexit.value = "false";
args.IsValid= false;
}
else
{
lableMessage.innerHTML = "Referral User does not exist";
lableMessage.style.color = "Red";
txtReferredBy.focus();
hdnrefuserexit.value = "false";
args.IsValid = false;
}
}
});
}
else
{
hdnrefuserexit.value="true;"
lableMessage.innerHTML = "";
args.IsValid = true;
}
}
<script type/>
<table>
<tr id="trReferral" runat="server" style="visibility: hidden;">
<td align="right" valign="top" class="input_label_right">
Referee UserID
</td>
<td align="left" valign="top">
<asp:TextBox ID="txtReferralID" CssClass="input_value" ValidationGroup="step1" runat="server" />
<asp:CustomValidator ID="CustomValidator2" ValidationGroup="step1" ControlToValidate="txtReferralID"
SetFocusOnError="true" ClientValidationFunction="GetName" runat="server" Display="Dynamic"
Visible="true" ErrorMessage="Referral User does not exist" />
<asp:Label ID="lblError1" runat="server" Text="" ForeColor="Green" Visible="true"></asp:Label>
</td>
</tr>
</table>
Anoth Page checkuser.aspx in Ajax folder
code in this file below.
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 DataObjects.General;
public partial class Ajax_checkuser : System.Web.UI.Page
{
#region Page Members
string SearchUserName = string.Empty;
#endregion
#region Events
/// <summary>
/// Page Load Event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
string SearchKey = Convert.ToString(Request.Form["q"]);
if (!string.IsNullOrEmpty(SearchKey))
{
string searchType = Convert.ToString(Request.Form["t"]);
if (!string.IsNullOrEmpty(searchType))
{
if (searchType == "referral")
{
GetUserName(SearchKey);
}
else if (searchType == "registration")
{
CheckUsersExists(SearchKey);
}
}
}
}
#endregion
#region Methods
/// <summary>
/// Get Provider Name by Referral ID Asyncronusly
/// </summary>
private void GetUserName(string SearchKey)
{
try
{
DataTable dt = PaperTab.BusinessObjects.User.UsersBo.GetUserByUserName(SearchKey);
if (dt != null)
{
if (dt.Rows.Count > 0)
{
string firstName = Convert.ToString(dt.Rows[0]["FirstName"]);
string lastName = Convert.ToString(dt.Rows[0]["LastName"]);
SearchUserName = firstName + " " + lastName;
Response.Write(SearchUserName);
}
else
{
Response.Write("false");
}
}
else
{
Response.Write("failed");
}
}
catch (Exception ex)
{
SearchUserName = string.Empty;
Response.Write("failed");
}
finally
{
}
}
/// <summary>
///
/// </summary>
/// <param name="SearchKey"></param>
private void CheckUsersExists(string SearchKey)
{
try
{
DataTable dt = PaperTab.BusinessObjects.User.UsersBo.GetUserByUserName(SearchKey);
if (dt != null)
{
if (dt.Rows.Count > 0)
{
Response.Write("true");
}
else
{
Response.Write("false");
}
}
else
{
Response.Write("failed");
}
}
catch (Exception ex)
{
SearchUserName = string.Empty;
Response.Write("failed");
}
finally
{
}
}
#endregion
}
No comments:
Post a Comment