Check User Name Availability....
------In Design----------------
<script type="text/javascript">
function ShowAvailability() {
PageMethods.CheckAssetTag(document.getElementById("<%=txtAssetTag.ClientID%>").value, OnSuccess);
}
function OnSuccess(response) {
var mesg = document.getElementById("mesg");
var mesg1 = document.getElementById("mesg1");
var btnsubmit = document.getElementById("ctl00_ContentPlaceHolderAdmin_imgBtnSubmit");
switch (response) {
case "true":
mesg.style.color = "green";
mesg.innerHTML = "<img src='../images/yes.png' title='Available'>";
mesg1.innerHTML = "";
btnsubmit.disabled = false;
break;
case "false":
mesg1.style.color = "red";
// mesg.innerHTML = "<img src='../images/no.png' title='Not Available'>";
//mesg1.innerHTML = "<b>Asset Tag already taken.!! Please Change.!!</b>";
alert("- Asset Tag already taken. Please Change.!");
btnsubmit.disabled = true;
// document.getElementById("<%=txtAssetTag.ClientID%>").value = "";
break;
case "error":
mesg.style.color = "red";
mesg.innerHTML = "Error occured";
break;
}
}
function OnChange() {
document.getElementById("mesg").innerHTML = "";
}
</script>
----------------------------------------------------
<asp:TextBox ID="txtAssetTag" runat="server" Width="135px" Height="18px" MaxLength="99"> </asp:TextBox>
<span id="mesg"></span>
<span id="mesg1"></span>
----------------
In Code Behind File
--------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
txtAssetTag.Attributes.Add("onchange", "OnChange();ShowAvailability();");
}
-------------------------------------------------------------
[System.Web.Services.WebMethod]
public static string CheckAssetTag(string AssetTag)
ALTER PROCEDURE proc_CheckAssetTagCodeAlreayExists
(
@AssetTag VARCHAR(50)
)
AS
BEGIN
SET NOCOUNT ON;
IF NOT EXISTS(SELECT * FROM AssetMaster WHERE AssetTag = @AssetTag)
SELECT 'true'
ELSE
SELECT 'false'
END
------------------------------------------------------------------
------In Design----------------
<script type="text/javascript">
function ShowAvailability() {
PageMethods.CheckAssetTag(document.getElementById("<%=txtAssetTag.ClientID%>").value, OnSuccess);
}
function OnSuccess(response) {
var mesg = document.getElementById("mesg");
var mesg1 = document.getElementById("mesg1");
var btnsubmit = document.getElementById("ctl00_ContentPlaceHolderAdmin_imgBtnSubmit");
switch (response) {
case "true":
mesg.style.color = "green";
mesg.innerHTML = "<img src='../images/yes.png' title='Available'>";
mesg1.innerHTML = "";
btnsubmit.disabled = false;
break;
case "false":
mesg1.style.color = "red";
// mesg.innerHTML = "<img src='../images/no.png' title='Not Available'>";
//mesg1.innerHTML = "<b>Asset Tag already taken.!! Please Change.!!</b>";
alert("- Asset Tag already taken. Please Change.!");
btnsubmit.disabled = true;
// document.getElementById("<%=txtAssetTag.ClientID%>").value = "";
break;
case "error":
mesg.style.color = "red";
mesg.innerHTML = "Error occured";
break;
}
}
function OnChange() {
document.getElementById("mesg").innerHTML = "";
}
</script>
----------------------------------------------------
<asp:TextBox ID="txtAssetTag" runat="server" Width="135px" Height="18px" MaxLength="99"> </asp:TextBox>
<span id="mesg"></span>
<span id="mesg1"></span>
----------------
In Code Behind File
--------------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
txtAssetTag.Attributes.Add("onchange", "OnChange();ShowAvailability();");
}
-------------------------------------------------------------
[System.Web.Services.WebMethod]
public static string CheckAssetTag(string AssetTag)
{-------------STORED PROC------------------------------------------------
string returnValue = string.Empty;
try
{
string consString = ConfigurationManager.ConnectionStrings["ATSConnectionString1"].ConnectionString;
SqlConnection conn = new SqlConnection(consString);
SqlCommand cmd = new SqlCommand("proc_CheckAssetTagCodeAlreayExists", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@AssetTag", AssetTag.Trim());
conn.Open();
returnValue = cmd.ExecuteScalar().ToString();
conn.Close();
}
catch
{
returnValue = "error";
}
return returnValue;
}
ALTER PROCEDURE proc_CheckAssetTagCodeAlreayExists
(
@AssetTag VARCHAR(50)
)
AS
BEGIN
SET NOCOUNT ON;
IF NOT EXISTS(SELECT * FROM AssetMaster WHERE AssetTag = @AssetTag)
SELECT 'true'
ELSE
SELECT 'false'
END
------------------------------------------------------------------
0 comments:
Post a Comment