How to Show Messenger-Like Popups Using AJAX
page 4 of 6
by Bilal Haidar
Feedback
Average Rating: 
Views (Total / Last 10 Days): 41630/ 64

Building the AJAX Service

In this final section of the article we will show you the simple AJAX Service that we have created that the client code will use to access the database and retrieve information about the number of records stored in the database.

Listing 6

[ScriptService]
public class InboxService: System.Web.Services.WebService
{
  [WebMethod]
  public int GetLatestNumberOfEmails()
  {
    int numberOfEmails = 0;
 
    using(SqlConnection conn = new SqlConnection
      (WebConfigurationManager.ConnectionStrings[0].ConnectionString))
    {
      using(SqlCommand cmd = new SqlCommand("GetLatestNumberOfEmails", conn))
      {
        cmd.CommandType = CommandType.StoredProcedure;
 
        conn.Open();
        numberOfEmails = (int)cmd.ExecuteScalar();
      }
    }
 
    return numberOfEmails;
  }
}

The first thing to notice is the ScriptService attribute located at top of the service name. This is very important if you want your Web service to be a script callable service. The above web service includes one Web method which is GetLatestNumberOfEmails that accesses the database and retrieves the total number of emails or records in the database.


View Entire Article

User Comments

Title: 2012 NFL jerseys   
Name: NIKE NFL jerseys
Date: 2012-05-20 11:39:22 PM
Comment:
[/pre]Cheap NFL,NBA,MLB,NHL
[url=http://www.jersey2shop.com/]Jerseys From China[/url]
[url=http://www.jersey2shop.com/]2012 nike nfl Jerseys[/url]
[url=http://www.jersey2shop.com/]cheap China Jerseys[/url]
[url=http://www.jersey2shop.com/]Sports Jerseys China[/url]
[url=http://www.jersey2shop.com/NFL-Jerseys-c68/]NFL Jerseys China[/url]
[url=http://www.jersey2shop.com/NBA-Jerseys-c77/]NBA Jerseys China[/url]
NHL Jerseys China
[url=http://www.jersey2shop.com/MLB-Jerseys-c94/]MLB Jerseys China[/url]NFL jerseys For Sale online.All Our Jerseys Are Sewn On and Directly From Chinese Jerseys Factory
[/pre]
[pre]We Are Professional China jerseys Wholesaler
[url=http://www.cheapjersey2store.com/]Wholesale cheap jerseys[/url]Cheap mlb jerseys
[url= http://www.cheapjersey2store.com/]2012 mlb all atar jerseys[/url]
[url= http://www.cheapjersey2store.com/ [/url]Cheap China Wholesael[/url]
[url= http://www.cheapjersey2store.com/]Wholesale jerseys From China[/url]
[url=http://www.cheapjersey2store.com/]2012 nike nfl Jerseys[/url]Free Shipping,Cheap Price,7 Days Deliver
[/pre]
[/pre]
We are professional jerseys manufacturer from china,wholesal
sports [url= http://www.cheapjersey2store.com/]Jerseys From China[/url]
[url=http://www.cheapjersey2store.com/NFL-Jerseys-c68]NFL jerseys China[/url]
[url=http://www.cheapjersey2store.com/NHL-Jerseys-c96/]NHL Jerseys China[/url]
[url=http://www.cheapjersey2store.com/NBA-Jerseys-c77/]NBA Jerseys China[/url]
[url=http://www.cheapjersey2store.com/MLB-Jerseys-c94/]MLB Jerseys China[/url]
[url= http://www.cheapjersey2store.com/]China Jerseys[/url],Free Shipping
[/pre]
[/pre]
We are professional jerseys manufacturer from china,wholesal
sports [url= http://www.jerseycaptain.com/]cheap jerseys sale online [/url]
[url= http://www.jerseycaptain.com/]2012 nike nfl Jerseys[/url]
[url=http://www.jerseycaptain.com/NFL-Jerseys-c68]cheap NFL jerseys China[/url]
[url=http://www.jerseycaptain.com/NHL-Jerseys-c96/]NHL Jerseys C
Title: Good Article   
Name: Vinod Mishra
Date: 2011-02-18 7:26:17 AM
Comment:
Its realy good article, help me to implement in our application, this also update my skill
Title: Thanks a lot   
Name: Richard
Date: 2011-02-03 10:50:34 AM
Comment:
Thanks for the source code. I started to learn Ajax and this is very good to start with Thanks again.
Title: Thanks   
Name: Salamander
Date: 2009-12-09 6:36:07 AM
Comment:
Thank you for this post. It was very useful for me. I love learning more news on such topics. Recently I have downloaded a great video from http://www.picktorrent.com torrent search engine which helps to understand this issue better. This source will also help you find much useful information for free.
Title: rabih k   
Name: Good Article
Date: 2009-11-13 1:20:07 AM
Comment:
Thank you bilal for the useful article.
Title: Amoun   
Name: Rabih
Date: 2009-09-25 10:09:15 AM
Comment:
nice one bilal,
did you try creating a user control out of it? it stops working. and the problem? in the generated scripts. let us know if it works for you.
Title: I liked your suggestion   
Name: Sunny
Date: 2009-01-10 1:33:25 AM
Comment:
Hey I Liked your suggestion
but i want to hav a popup to work like a messenger popup
wen ever value in the database changes the popup must cum without the need of thec client to refresh the page ?
Title: cant use   
Name: sunil deshkar
Date: 2008-12-18 6:52:56 AM
Comment:
I cant used the script. because cant understand .
Title: Suggestion   
Name: Sameer
Date: 2008-10-23 4:30:05 AM
Comment:
Can i use it as scheduler?
I want to design an application in which a user receives an reminder.
Ex. My database contains email-id,date of birth of candidates then,
whenever the user opens the site, he is suppose to get a message for his birthday if he
is having bithday on that day!
(dot Net is action driven,is it possible ?)
kindly reply!!
Title: GENIOUS   
Name: Sameer
Date: 2008-10-23 4:15:21 AM
Comment:
I liked it !!!
Title: Error   
Name: Tim
Date: 2008-10-22 3:06:32 PM
Comment:
Actually, I get an error telling my that "The server method 'GetLatestNumberOfEmails' failed with the following error - There was an error processing the request.
Title: Erro   
Name: Tim
Date: 2008-10-22 3:04:30 PM
Comment:
It will run on my local machine, bur nothing happens when I try ot run on my server. Any suggestions?
Title: HI   
Name: JUAN PABLO
Date: 2008-07-21 6:54:03 PM
Comment:
very usefull ypur comment
Title: This does not work   
Name: Ram
Date: 2008-07-11 12:26:20 PM
Comment:
hi i am using the same code for my project, it works when i use a simple aspx page but when i use same thing through masterpage it does not work. Any Solutions
Title: facing problem   
Name: azeez
Date: 2008-01-25 4:47:22 AM
Comment:
Hi

i am using this code in my application(c#,2005) in master page . in my appliccation i am getting connectionstring from session values . so in inboxservice.cs i changed the coding as getting connection string from session . but its giving following error :

Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive .

and also

$get("UpdateProgress1").style.visibility= "visible"; this line giving following error :
undefined ($get("UpdateProgress1") is null)
Title: Nice Article but some doubts   
Name: Siva
Date: 2007-10-19 9:22:34 AM
Comment:
hi bilal

nice article but i have some doubts
what is the significance of $ in the javascript

could you please this more details

regards
siva
Title: Nice Article   
Name: siva
Date: 2007-10-19 7:11:13 AM
Comment:
Learnt new concepts with how to use AJAX Extensions
Title: How to Show Messenger-Like Popups Using AJAX   
Name: john
Date: 2007-10-10 4:04:05 PM
Comment:
I like it!
Title: Forget all about this   
Name: Márcio Duarte
Date: 2007-08-22 9:07:30 AM
Comment:
Hey you...

Forget all about this... Open your mind... Enhance your World...

Using the JQuery and Ext JS will give you more facility in JavaScript coding.

And more... it's open source... do you need to know how incredible things have been done with...

http://jquery.com and http://extjs.com/

This will change your way to see de JavaScript and the Client-Side Programming.

Good Code for all.
Title: Demo   
Name: Divyesh
Date: 2007-08-02 6:38:31 AM
Comment:
You should provide online demo of your source code (sample project)
Title: Looks awsome   
Name: Nazar Rizvi
Date: 2007-07-27 5:28:22 PM
Comment:
This would be so helpful. It could have been even betterif we had something of this sort for the windows apps.
Title: Thanks   
Name: Anju
Date: 2007-07-27 7:58:33 AM
Comment:
Good
Title: Excallent   
Name: santosh
Date: 2007-07-27 7:38:34 AM
Comment:
IT is new feature but it would be much great if there is no web service implementation in the useage of this feature.

is it possible to generate a code with same functionality without using web services? if so please guide me.

Thanks
Title: Not so good   
Name: Marcos
Date: 2007-07-25 9:45:07 PM
Comment:
Using settimeout is not a good choice.

If you executing something on server and the StartChecking run, the server will execute twice the previously server process.
Title: GOOG   
Name: Mr. Duc
Date: 2007-07-25 1:38:18 AM
Comment:
good, I love it, and I use example in my project. Thank you very much
Title: Re: Hiren   
Name: Bilal Haidar [MVP]
Date: 2007-06-25 1:50:19 AM
Comment:
Hiren,
You can visit my site here: http://bhaidar.net/cs/archive/2007/04/18/telerik-c-vb-net-converter.aspx

You can convert the code from C# to VB easily!

Hope this helps,
regards
Title: Very Nice Example   
Name: Hiren Jatakia
Date: 2007-06-25 1:41:04 AM
Comment:
Hello Bilal,
This is exactly i want, Nice article, but can i have VB version of this example, cause i require this in VB.net format not in c#, if u can send it to me, it would be very helpful for me......
Title: Nice codes   
Name: PAwan Kumar
Date: 2007-06-24 4:59:04 AM
Comment:
Nice tutorial ....keep it up
Title: database   
Name: somuvas
Date: 2007-06-20 1:55:22 AM
Comment:
this is db connections
Title: One Question Though   
Name: AzamSharp
Date: 2007-06-14 12:44:52 PM
Comment:
Hi Bilal,

Great article as usual. I have one question though. Is there any special reason that you used the UpdateProgress control?

Thanks,
Azam
Title: Very Very Nice Work   
Name: AzamSharp
Date: 2007-06-13 5:57:37 PM
Comment:
Hi Bilal,

Very very nice work. :)

Thanks,
Title: SW engineer   
Name: Vinh
Date: 2007-06-13 10:36:29 AM
Comment:
It is good article. Simple and easy to follow.
Title: Re:   
Name: Bilal Haidar [MVP]
Date: 2007-06-13 9:28:10 AM
Comment:
I never publish anything that it doesn't work!

Plus, there is a technical editing for this article! So I am sure it works!! Are you facing any problem?

Regards
Title: R u sure!   
Name: Vijay KArla
Date: 2007-06-13 4:28:25 AM
Comment:
Bilal, R u sure that it works?
Title: Great work   
Name: Sandeep Acharya
Date: 2007-06-13 3:56:32 AM
Comment:
Hi,

I have already gone thru some of your prev articles and this one also carries the excellence with no exception.

Keep providing us such nice stuffs.

Thanks

Sandeep Acharya
Title: Good Article   
Name: Joydip Kanjilal
Date: 2007-06-13 1:58:54 AM
Comment:
Hi Bilal,

This is a nice article. Keep this good work going.

Best,

Joydip
Title: It's Good   
Name: Anjali Kataria
Date: 2007-06-12 10:12:05 PM
Comment:
Feature that u explain with an examples Its good. Good Work keep Up GOOD LUCK
Title: Very Good Article   
Name: Haissam Abdul Malak
Date: 2007-06-12 1:22:24 AM
Comment:
Bilal, it was nice to see such an implementation. keep up the good work

Regards,






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-24 1:28:21 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search