Click here to Skip to main content
15,886,519 members
Articles / Web Development / ASP.NET

Creating a Poll System Using ASP.NET 2.0 Callbacks

Rate me:
Please Sign up or sign in to vote.
4.36/5 (22 votes)
18 Nov 20074 min read 107.7K   2.8K   52  
An article on how to create an AJAX enabled polling system using ASP.NET client callbacks.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace WeeklyPollDemoWebApps
{
    public partial class TestingSessionErrors : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            GetObjectFromSession();
        }

        private string GetObjectFromSession()
        {
            if (Session["UserName"] == null)
                throw new ArgumentNullException("UserName is null","UserName is null. Your session has expired. <res> Please log on to the system to start a new session </res>");

            return Session["UserName"] as String; 

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            throw new InvalidOperationException("You can not allowed to perform this operation. <res> Please check with your system administrator for your rights </res>"); 
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            throw new DivideByZeroException("Divide by Zero Error. <res> You are trying to divide a number by zero </res>");
            
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            string connectionString = "Server=localhost;Database=BABA;Trusted_Connection=true";

            SqlConnection myConnection = null;
            try
            {
                myConnection = new SqlConnection(connectionString);
                myConnection.Open();
            }
            catch (Exception ex)
            {
                throw new ArgumentNullException("The database does not exist. <res> Please make sure the database you are trying to connect exists. </res>"); 
            }
            finally { myConnection.Close(); } 

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
My name is Mohammad Azam and I have been developing iOS applications since 2010. I have worked as a lead mobile developer for VALIC, AIG, Schlumberger, Baker Hughes, Blinds.com and The Home Depot. I have also published tons of my own apps to the App Store and even got featured by Apple for my app, Vegetable Tree. I highly recommend that you check out my portfolio. At present I am working as a lead instructor at DigitalCrafts.




I also have a lot of Udemy courses which you can check out at the following link:
Mohammad Azam Udemy Courses

Comments and Discussions