Thursday, September 20, 2012

How to check user name exists or not using jquery

Hi friends!
Whenever we create a registration form we need to check duplicate user name.Today ,I am writing how we can check this duplicate user name using jquery.I hope it will be helpfull for you.

So let's start

We need three things only
1. Web method : I hope you are familiar with web services
2. Registration form
3.jquery .

Also don't forget to add jquery library on your page.

<script src="../script/jquery-1.4.1.min.js" type="text/javascript"></script>


Now let's see how we can check the username with server data through jquery.

1. Take an aspx page with a textbox and span control
<asp:TextBox ID="txtUserNameReg" Width="200px" runat="server"></asp:TextBox>
<span id="Message"></span>

2. create a web method in our .cs page


 
[System.Web.Services.WebMethod]

public static string CheckUserName(string userName)

{
string returnValue = string.Empty;

string conString = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;

SqlConnection sqlConn = new SqlConnection(conString);

try

{
SqlCommand sqlCmd = new SqlCommand("CheckUserName", sqlConn);

sqlCmd.CommandType = CommandType.StoredProcedure;

sqlCmd.Parameters.AddWithValue("@UserName", userName.Trim());

sqlConn.Open();
int success = int.Parse((sqlCmd.ExecuteScalar().ToString()));

if (success == 1) //shows user name not available

{

returnValue ="Not Available";


}
else if (success == 0)//shows user name available is available

{

returnValue =
"Available";

}

}
catch

{

}
finally

{

sqlConn.Close();

}
return returnValue;

}
 





Now it's time to use lovely jquery function to check and display message

Paste this on aspx page in head master content
<script type="text/javascript" >

var $j = jQuery.noConflict(); //u can use this when using ajax for no confliction.

var msgbox = $j("#status");

$j(document).ready(function() {

$j("#<%=txtUserNameReg.ClientID %>").blur(function() {

$j.ajax({





type:
"POST",

url: "Registration.aspx/checkUserName",

data: "{'userName':'" + $j("#<%=txtUserNameReg.ClientID %>").val() + "'}",

contentType: "application/json; charset=utf-8",

dataType: "json",

success: function(message) {

if (message.d =='Available') {



$j("#<%=txtUserNameReg.ClientID %>").removeClass("notavailablecss");



$j(
"#<%=txtUserNameReg.ClientID %>").addClass("availablecss");

$j("#status").html('<img src="../Images/a.png"> <font color="Green"> Available </font>');







$j(
"#<%=Button1.ClientID %>").removeAttr('disabled');//enable submit button is available





}
else {



//





$j(
"#<%=txtUserNameReg.ClientID %>").removeClass("availablecss");



$j(
"#<%=txtUserNameReg.ClientID %>").addClass("notavailablecss");

$j("#status").html('<img src="../Images/n.png"> <font color="red">Not Available </font>');

$j("#<%=Button1.ClientID %>").disabled=true;

$j("#<%=Button1.ClientID %>").attr("disabled", "true");//disable submit button is  not available



}

},

error:
function(errormessage) {



$j("#status").html(errormessage.responseText);

}

});

});

});





</script>



at last use this css

<style type="text/css">

#status

{

font-size:11px;

margin:10px;

}

.availablecss

{

background-color:#CEFFCE;

border:1px solid green;

}

.notavailablecss

{

background-color:#FFD9D9;

border:1px solid red;

}

</style>

Thats it. How it is simple? Just try my code and enjoy jquery with server side data.

Any confusion? Please mail me: mkumar.soft@gmail.com

If  you like my post,Please give your comments .

enjoy coding ......

Thursday, August 2, 2012

How to use Session in Web Services

We can use session in our web service simply by adding one attribute

In the web method section we need to add just enablesession=true;
here is systax


[webmethod(EnabledSession=true)]
my webmethod
{


}



enjoy coding..

Delete duplicate records from a sql table using cte

Here is a simle query to delete duplicate records from sql table using CTE(Compatible for  sql 2005 and 2008)
 
;WITH emptable (FirstName,LastName, dpcount)
AS
(
SELECT FirstName,LastName,
ROW_NUMBER()OVER(PARTITIONBY FirstName, LastName ORDERBY FirstName) AS dpcount
FROM emptable(table name)
)
DELETE
FROM emptable
WHERE dpcount> 1
 
 
 
Enjoy coding..
 

Monday, June 11, 2012

How to use aspx page inside the asp page

Dear Developer,
Few days ago ,I had a requirement to develope a web page in the classical asp. But I don't know ASP. That was very big problem for me. Project was in ASP.So, what  could do?. Googlling........ yes!
I googled and find that I can do, and I did. How?....

In the asp page I wrote this inside a <td>
      <iframe id="IFR" name = "IFR"  src="ASPXpage.aspx" width="1000px" height="330px"       marginheight=0 marginwidth=0  frameborder="0"
 scrolling="Yes" ALLOWTRANSPARENCY="TRUE" style="border:1px;"></iframe>


I used this in my asp page and each and every features of asp.net is running well.
We can send required data in aspx page by querystring as normally we do.
And important thing is that we don't need to worry about asp page session ,this is maintained.



Enjoy coding!




Convert Html to Pdf in azure function and save in blob container

 In this post  I am going to create an azure function ( httpTrigger ) and send html content  which will be converted into PDF and save in bl...