Thursday 3 January 2013

Calling javascript function from CodeBehind with C#


Javascript works from the client side while server code requires server processing. 
It is not possible to direcly invoke a client event through a server event. However there exists a fairly simple methods to achieve this. I will explain one simple way to do it.

Injecting a javascript code into a label control

This is one of the simplest method to call a javascript function from code behind. You need to do the following:

1.     Create a new website project
2.     Add a label and button control on your Default.aspx page
3.     You body part of the markup should now look something like this: 

<body> 
    <form id="form1" runat="server"> 
    <div> 
        <asp:Label ID="lblJavaScript" runat="server" Text=""></asp:Label> 
        <asp:Button ID="btnShowDialogue" runat="server" Text="Show Dialogue" /> 
    </div> 
    </form> 
</body> 

4.     Add a javascript function to show a message box as shown below: 
<head runat="server"> 
    <title>Calling javascript function from code behind example</title> 
        <script type="text/javascript"> 
            function showDialogue() { 
                alert("this dialogue has been invoked through codebehind."); 
            } 
        </script> 
</head>
5.     Now double-click on the button and add the following code: 
lblJavaScript.Text = "<script type='text/javascript'>showDialogue();</script>";

6.     Run your project and click the Show Dialogue button

A message box will be displayed as shown below: 
screen shot of client side message box

3-Tier Architecture in ASP.NET with C# tutorial


   
In 3 tier programming architecture, the application development is broken into three main parts; these are: Presentation layer(PL), Business Acess Layer(BAL) and Data Access Layer(DAL). These separations ensure independent development of those layers such that a change in one does not affect the other layers. For instance a change in the logic of the DAL layer does not affect the the BAL nor the presentation layer. It also makes testing easier in that a whole layer can be replaced with a stub object.

 For example instead of testing the whole application with an actual connection to database, the DAL can be replaced with a stub DAL for testing purposes. The DAL deals with actual database operations. These operations are inserting, updating, deleting and viewing. The BAL deals with the business logic for a particular operation. The PL has the user controls for interacting with the application.

3-Tier programming architecture also enables re-use of code and provides a better way for multiple developers to work on the same project simultaneously.
  1. Start a new website project
  2. Design you page as shown below,
    3 tier form design
  3. Add sub-folders and class objects within the App_code folder as shown below,
    3 tier classes
  4. Code for the add button is shown below,
    protected void cmdAdd_Click(object sender, EventArgs e)
    {
        CustomerBAL cBal = new CustomerBAL();
        try
        {
            if (cBal.Insert(txtCustomerID.Text, txtFirstName.Text, txtLastName.Text) > 0)
            {
                lblMessageLine.Text = "Record inserted successfully.";
            }
            else
            {
                lblMessageLine.Text = "Record not inserted.";
            }
        }
        catch (Exception ex)
        {
            lblMessageLine.Text = ex.Message;
        }
        finally
        {
            cBal = null;
        }
  5. code for CustomerBAL.cs
    using System;
    using System.Collections.Generic;
    using System.Web;
    ///
    /// Summary description for CustomerBAL
    ///

    public class CustomerBAL
    {
        public CustomerBAL()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public int Insert(string CustomerID, string FirstName, string LastName)
        {
            CustomerDAL cDal=new CustomerDAL();
            try
            {
                return cDal.Insert(CustomerID, FirstName, LastName);
            }
            catch
            {
                throw;
            }
            finally
            {
                cDal = null;
            }
        }
  6. Code for CustomerDAL.cs
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Data.SqlClient;
    using System.Data;

    ///
    /// Summary description for CustomerDAL
    ///

    public class CustomerDAL
    {
        public CustomerDAL()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public int Insert(string CustomerID, string FirstName, string LastName)    public int Insert(string CustomerID, string FirstName, string LastName)
        {
            //declare SqlConnection and initialize it to the settings in the section of the web.config
            SqlConnection Conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbConnectionString"].ConnectionString);
            //===============================
            //prepare the sql string
            string strSql = "insert into t_Customers(CustomerID,FirstName,LastName) ";
            strSql = strSql + "values(@CustomerID,@FirstName,@LastName)";

            //declare sql command and initalize it
            SqlCommand Command = new SqlCommand(strSql, Conn);

            //set the command type
            Command.CommandType = CommandType.Text;

            try
            {
                //define the command parameters
                Command.Parameters.Add(new SqlParameter("@CustomerID", SqlDbType.VarChar));
                Command.Parameters["@CustomerID"].Direction = ParameterDirection.Input;
                Command.Parameters["@CustomerID"].Size = 20;
                Command.Parameters["@CustomerID"].Value = CustomerID;

                Command.Parameters.Add(new SqlParameter("@FirstName", SqlDbType.VarChar));
                Command.Parameters["@FirstName"].Direction = ParameterDirection.Input;
                Command.Parameters["@FirstName"].Size = 25;
                Command.Parameters["@FirstName"].Value = FirstName;

                Command.Parameters.Add(new SqlParameter("@LastName", SqlDbType.VarChar));
                Command.Parameters["@LastName"].Direction = ParameterDirection.Input;
                Command.Parameters["@LastName"].Size = 25;
                Command.Parameters["@LastName"].Value = LastName;

                //open the database connection
                Conn.Open();
                //execute the command
                return Command.ExecuteNonQuery();
            }
            catch
            {
                throw;
            }
            finally
            {
                Command.Dispose();
                Conn.Dispose();
            }
        }
    }
  7. Set the connection string on the web.config file
  8. Run the project

Apple iPad mini‘s ‘inferior‘ screen made by Samsung




Apple's iPad mini appears to include an LCD display driver from South Korea's Samsung Electronics, a key supplier but also the Silicon Valley tech giant's fiercest rival in a global mobile-device war.

The iPad mini, to be available in stores on Friday, includes Apple's A5 processor, SK Hynix flash memory and a number of chips from Fairchild Semiconductor International, according to electronics repair company iFixit, which acquired one early and opened it on Thursday.

Apple and Samsung are engaged in patent disputes across 10 countries as they vie for market share in the booming mobile industry, and Apple is believed to be seeking ways to rely less on Samsung. But Samsung remains a key supplier for Apple, manufacturing its application processors and providing other components.

The 7.9-inch iPad mini marks the iPhone-maker's first foray into the smaller-tablet segment. Apple hopes to beat back incursions onto its home turf of consumer electronics hardware, while safeguarding its lead in a larger tablet space - one that even deep-pocketed rivals like Samsung have found tough to penetrate.

How cloud computing can hurt jobs



Cloud computing, regarded as a boon for enterprises, could rain on the party of distributors and resellers who are now an integral part of the technology sales ecosystem. In developed economies, the community of resellers is already shrinking as software and hardware companies engage directly with enterprises. In India, where cloud adoption is just about gaining pace, the drizzle has begun.

"Given the nature of the cloud business, we see that it could be a threat. But the adoption rate is very slow and, therefore, we have a few years before we see signs of trouble," said Ratnesh Rathi, secretary at Computer & Media Dealers Association, whose 350-odd members do business in and around Pune.

Across India, some Rs 61,500 crore worth of hardware and Rs 18,000 crore worth of software products are sold every year, according to industry body Nasscom. And about 23,000 distributors, resellers and retailers - often called channel partners - are responsible for about four-fifths of total sales.

As enterprises move to the cloud for their computing requirements, both hardware and software are delivered over the internet rather than as physical assets that reside on customers' premises. This calls into question the role of channel partners.

Change is on the way, and it could be taking place sooner than many anticipate. A recent study by the Society for Information Management captured early signs of this change. Enterprises used to spend about 32% of their IT budget on in-house hardware in 2011, but that is down to 24% in 2012.

Gartner estimates that $326 million (Rs 1,760 crore) worth of cloud computing services were consumed in India, including software and hardware. Less than one in ten enterprises have adopted cloud computing at present, but the market is expected to grow at an average of 50% every year till 2015.

"Channel partners are facing the ripple effect of the changing times. As clients move to an operational expenditure model, vendors are asking suppliers to learn and change," said KR Chaube, director at Trade Association of Information Technology, or Tait, a group that represents the interests of distributors and resellers in and around Mumbai. "There is a lack of clarity about the cloud among channel partners."

Some channel partners are beginning to adapt to the changing environment. Among them are Bangalore-based Value Point Systems, a Hewlett-Packard partner for nearly two decades, and Kolkata-based Supertron Electronics that distributes Acer and Dell products. By investing in data centres and offering storage as a service, they are looking to evolve from mere box-pushers to value-added technology solution providers.

Ingram Micro, one of the biggest distributors with revenues of more than Rs 10,000 crore, announced partnerships with Microsoft, Salesforce, Netmagic, Zoho and Ramco to offer cloud-based solutions in both software and hardware.

But those such as Ingram and Value Point are exceptions to the rule. Few channel partners are aware of what they need to do to survive and fewer still are capable and equipped to do it. Vendors such as Microsoft and Dell try to help channel partners but ignorance and inertia stand in the way.

While channel partners in developed markets like Australia and Japan already use cloud-based solutions, Indian partners are less willing to change because their business is yet to be impacted in a significant way, according to a senior executive at Oracle.

"They are still getting business within their specialisation as a hardware-only partner or a network-only partner and this is making them unwilling to change," said Stuart Long, chief technology officer and senior sales consulting director for the Systems Division in Oracle's Asia Pacific and Japan region.

Senior analyst at Forrester Research Tirthankar Sen said that unless partners start building on the "cloud-quotient," they rule out the possibility of being able to growth with the cloud.

According to market researcher AMI Partners, only about 35% of channel partners are offering cloud-based solutions. The rest are exposed to the risk of becoming irrelevant as the cloud grows in size.

"At the end of the day not everybody may make it." said Microsoft India managing director Sanket Akrekar.

Tracing Microsoft‘s journey from text to touch


With recent release of the touch-centric Windows 8 software, Microsoft continues more than three decades of making operating systems for personal computers.

Microsoft got its start on PCs in 1981 through a partnership with IBM. Microsoft made the software that ran IBM's hardware, and later machines made by other manufacturers. That first operating system was called MS-DOS and required people to type instructions to complete tasks such as running programs and deleting files.

It wasn't until 1985 that Microsoft released its first graphical user interface, which allowed people to perform tasks by moving a mouse and clicking on icons on the screen. Microsoft called the operating system Windows.

Windows 1.0 came out in November 1985, nearly two years after Apple began selling its first Macintosh computer, which also used a graphical operating system. Apple sued Microsoft in 1988 for copyright infringement, claiming that Microsoft copied the "look and feel" of its operating system. Apple lost.

Microsoft followed it with Windows 2.0 in December 1987, 3.0 in May 1990 and 3.1 in April 1992.

In July 1993, Microsoft released Windows NT, a more robust operating system built from scratch. It was meant as a complement to Windows 3.1 and allowed higher-end machines to perform more complex tasks, particularly for engineering and scientific programs that dealt with large numbers.

Microsoft had its first big Windows launch with the release of Windows 95 in August 1995. The company placed special sections in newspapers, ran television ads with the Rolling Stones song "Start Me Up" and paid to have the Empire State Building lit up in Windows colors.

Comedian Jay Leno joined co-founder Bill Gates on stage at a launch event at the company's headquarters in Redmond, Wash.

"Windows 95 is so easy, even a talk-show host can figure it out," Gates joked.

The hype worked: Computer users lined up to be the first to buy it. Microsoft sold millions of copies within the first few weeks. Windows 95 brought built-in Internet support and "plug and play" tools to make it easier to install software and attach hardware. Windows 95 was far better - and more successful - than its predecessor and narrowed the ease-of-use gap between Windows and Mac computers.

At around the same time, Microsoft released the first version of its Internet Explorer browser. It went on to tie IE and Windows functions so tightly that many people simply used the browser over the once-dominant Netscape Navigator. The US Justice Department and several states ultimately sued Microsoft, accusing it of using its monopoly control over Windows to shut out competitors in other markets. The company fought the charges for years before settling in 2002.

The June 1998 release of Windows 98 was more low-key than the Windows 95 launch, though Microsoft denied it had anything to do with the antitrust case.

Windows 98 had the distinction of being the last with roots to the original operating system, MS-DOS. Each operating system is made up of millions of lines of instructions, or code, written in sections by programmers. Each time there's an update, portions get dropped or rewritten, and new sections get added for new features. Eventually, there's nothing left from the original.

Microsoft came out with Windows Me a few years later, the last to use the code from Windows 95. Starting with Windows 2000, Microsoft worked off the code built for NT, the 1993 system built from scratch.

The biggest release since Windows 95 came in October 2001, when Microsoft launched Windows XP at a hotel in New York's Times Square. Windows XP had better internet tools, including built-in wireless networking support. It had improvements in media software for listening to and recording music, playing videos and editing and organizing digital photographs.

Microsoft's next major release didn't come until Vista in November 2006. Businesses got it first, followed by a broader launch to consumers in January 2007. Coming after years of virus attacks targeting Windows machines and spread over the Internet, the long-delayed Vista operating system offered stronger security and protection. It also had built-in parental-controls settings.

But many people found Vista slow and incompatible with existing programs and devices. Microsoft launched Windows 7 in October 2009 with fixes to many of Vista's flaws.

Windows 7 also disrupted users less often by displaying fewer pop-up boxes, notifications and warnings - allowing those that do appear to stand out. Instead, many of those messages get stashed in a single place for people to address when it's convenient.

In a sign of what's to come, Windows 7 was able to sense when someone is using more than one finger on a touchpad or touch screen, so people can spread their fingers to zoom into a picture, for instance, just as they can on the iPhone.

Apple released its first iPhone in 2007 and the iPad in 2010. Devices running Google's Androidsystem for mobile devices also caught on. As a result, sales of Windows computers slowed down. Consumers were delaying upgrades and spending their money on new smartphones and tablet computers instead.

Windows 8 and its sibling, Windows RT, represent Microsoft's attempt to address that. It's designed to make desktop and laptop computers work more like tablets.

Windows 8 ditches the familiar start menu on the lower left corner and forces people to swipe the edges of the screen to access various settings. It sports a new screen filled with a colorful array of tiles, each leading to a different application, task or collection of files. Windows 8 is designed especially for touch screens, though it will work with the mouse and keyboard shortcuts, too.

Microsoft and PC makers alike had been looking to Windows 8 to resurrect sales. Microsoft's recent launch event was of the caliber given for Windows 95 and XP.

But with Apple releasing two new iPads, Amazon.com shipping full-sized Kindle Fire tablets and Barnes & Noble refreshing its Nook tablet line next month, Microsoft and its allies will face competition that is far more intense than in the heyday of Windows 95 and XP.

Sample Text

Muthukumar. Powered by Blogger.

About Me

My photo
Hi i am Muthu kumar,software engineer.