Infolink

 

Search This Blog

Nov 30, 2012

String.Format in Asp.Net (PART-2)

Culture Information

string.format also provides a method which accepts a CultureInfo argument, as an IFormatProvider. This is important when trying to write portable and localisable code, as, for example, month names will change according to the local culture of the machine you are running on. Rather than simply call the standard String.Format you should consider always calling the overloaded culture method. If you don't need to specify a culture you can use the System.Globalization.CultureInfo.InvariantCulture. This will then default your formatting to English, as opposed to the culture of the current thread.

String.Format in Asp.Net (PART-1)

Formatting Strings

There's not much formatting that can be applied to a string. Only the padding / alignment formatting options can be applied. These options are also available to every argument, regardless of type.
example output
String.Format("--{0,10}--", "test"); --      test--
String.Format("--{0,-10}--", "test"); --test      --

ArrayList in Asp.net

The ArrayList object is a collection of items containing a single data value.

Items are added to the ArrayList with the Add() method.

The following code creates a new ArrayList object named books and three items are added:
  ArrayList books = new ArrayList();
  books.Add(”book1");
  books.Add(”book2");
  books.Add(”book3");

Nov 29, 2012

How to create MVC (model view controller) views faster by using HTML helper classes

MVC using HTML helper classes 

<table width="50%" runat="server" id="tbl1">
    <tr>
    <td>Student Id:</td>
    <td><asp:TextBox runat="server" ID="txt1"></asp:TextBox></td></tr>
    <tr>
    <td>Student Name:</td>
    <td><asp:TextBox runat="server" ID="txt2"></asp:TextBox></td></tr>
    <tr>
    <td>Student Percentage:</td>
    <td><asp:TextBox runat="server" ID="txt3"></asp:TextBox></td></tr>
    <tr>
    <td colspan="2" align="center"><asp:Button ID="Button1" runat="server" Text="Button" /></td>
    </tr>
</table>


How to pass data from controllers to views in ASP.NET MVC ?

The controller gets the first hit and loads the model. Most of the time we would like to pass the model to the view for display purpose.

As an ASP.NET developer your choice would be to use session variables, view state or some other ASP.NET session management object.

How to create a simple ASP.NET MVC data entry screen?

Creating simple MVC data entry screen

Every project small or big has data entry screens. In this lab we will create a simple customer data entry screen as shown in the below figure.



As soon as the end user enters detail and submits data it redirects to a screen as shown below. If he enters amount less than 100 it displays normal customer or else it displays privileged customer.

Basic MVC

The Model

Models are the main component of your app, which is usually; what is stored and retrieve from the database, in our app, it will the tweet info and text.

The View

Views are the date in formatted form, delivered to the user. Here it will be the HTML pages.

The Controller

Controllers are the components that respond to all user requests, decide the appropriate response; which might be render a view, redirect to other URI or many other things.

Pros and Cons
  • Pros
It has many pros, but these are the most remarkable:
  1. Full control over the HTML, CSS, and JavaScript code, helping you to write clean, standards-compliant markup
  2. It's Extensible which means that you can use a default component, or reconfigure it, or even use another component
  3. HTTP friendly, it gives you total control over the requests passing between browser and server
  4. Testability of MVC makes it simple to unit test the logic that is specific to a page, by testing controller methods
  • Cons
It does not really have many cons compared to its pros:
  1. The lake of drag and drop component in WebForms, despite that JQuery and other JavaScipt library overcome this problem
  2. It's not as easy as WebForms, you should understand the role of each component individually and all of them together.

Nov 28, 2012

How to create a simple model in ASP.NET MVC and display the same?(PART-4)

Step1:- Create a simple class file

The first step is to create a simple customer model which is nothing but a class with 3 properties code, name and amount. Create a simple ASP.NET MVC project, right click on the model folder and click on add new item as shown in the below figure.


Nov 26, 2012

ASP.NET MVC (PART-3)

MVC stands for "Model-View-Controller", which is a very old (but still very useful) design pattern. This design pattern will split your application in 3 different parts ("model", "view", "controller"). "Seperation of concern" is one of it´s main benefits.

Nov 25, 2012

MVC 2 - Dropdownlist with JSON

I setup the Database and LinqToSql classes for my app. The table structure is MeterTypes > MeterCollections > MeterUsages. Where a MeterType is the top level (ie. Electricity, Gas, Waste, etc.) the MeterCollections are the next level down (a MeterType may contain many of these, for Electricity I have Peak and Off-Peak) and MeterUsage is the actual usage on a meter for that MeterCollection.

OOPS Concepts (PART-2)

Multiple inheritance

Multiple inheritance is the possibility that a child class can have multiple parents. Human beings have always two parents, so a child will have characteristics from both parents.

In OOP, multiple inheritance might become difficult to handle because it allows ambiguity for the compiler. There are programming languages such as C++ that allow multiple inheritance; however, other

programming languages such as Java and the .NET Framework languages do not allow multiple inheritance. Multiple inheritance can be emulated in .NET using Multiple Interface Inheritance.

Popup window

Here I am going make custom model popup with using JQuery. Its looks very Attractive rather than the simple alert box in Asp.Net.

In my application, i would like to use the popup window concept. When the user clciks a button, a popup window should appear, with a textbox to enter a value. on closing the popup window, the user entered value should get saved into a table.

Nov 24, 2012

Execute SP_UPDATESTATS

The query optimizer uses the statistics to create the query plan to improve the query performance. The query optimizer automatically generates the necessary statistics to build high quality query plan to improve the performance of the query.

Session State in Asp.Net

Session State

Sometimes you want your web page to 'stay alive'. That is, if a user is filling out a complicated form, you do not want the session to time out before they are finished. The user could get very angry and rightfully so: You might even get yelled at!

Creating a Tag Cloud for Your ASP.NET Blog

Introduction

Most of the blogs display a set of tags or keywords in the form of a Tag Cloud. A tag cloud presents the keywords in font sizes proportional to the number of blog posts having that tag. If you are using some blogging website or using some open source blogging engine you already have a tag cloud ready. However, if you are building your own blog engine or website you will need to build the tag cloud on your own. This article shows how to do just that.

What is a multicast delegate?

A MulticastDelegate has a linked list of delegates, called an invocation list, consisting of one or more elements. When a multicast delegate is invoked, the delegates in the invocation list are called synchronously in the order in which they appear. If an error occurs during execution of the list then an exception is thrown

decimal and numeric (Transact-SQL)

Decimal and numeric

Numeric data types that have fixed precision and scale.

decimal [ (p[ ,s] )] and numeric[ (p[ ,s] )]
  • Fixed precision and scale numbers. When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1. The ISO synonyms for decimal are dec and dec(p, s). numeric is functionally equivalent to decimal.
  • p (precision)
  • The maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision of 38. The default precision is 18.
  • s (scale)
  • The maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through p. Scale can be specified only if precision is specified. The default scale is 0; therefore, 0 <= s <= p. Maximum storage sizes vary, based on the precision.
Precision Storage bytes

1 - 9       5

10-19     9

20-28    13

29-38    17

As per my understanding NUMERIC(18, 10) column would take 18 decimal digits to the left of the decimal point and 10 to the right.

Example:

SELECT CAST(1234567891234567.34 AS NUMERIC(18,2))  --Works
SELECT CAST(1234567891234567.34 AS NUMERIC(18,10)) --fails with Arithmetic overflow error


it is clear that, in the first case from the statement NUMERIC(18,2) the total digits are 18 and 16 digits are available to the left of decimal, whereas 1234567891234567 are 16 digits. Hence, there is no error.
In the second case, from the statement NUMERIC(18,10), 8 digits are available to the left of decimal, but 1234567891234567 are 16 digits which is more than 8 digits. Hence, Arithmetic overflow error occurs.

Nov 18, 2012

A simple ASP.NET MVC example to demonstrate Model, View and Controller

MVC Tutorial (PART-1)

The Model

Models are the main component of your app, which is usually; what is stored and retrieve from the database, in our app, it will the tweet info and text.

The View

Views are the date in formatted form, delivered to the user. Here it will be the HTML pages.

The Controller

Controllers are the components that respond to all user requests, decide the appropriate response; which might be render a view, redirect to other URI or many other things.

Pros and Cons
 
Pros

It has many pros, but these are the most remarkable:
  • Full control over the HTML, CSS, and JavaScript code, helping you to write clean, standards-compliant markup
  • It's Extensible which means that you can use a default component, or reconfigure it, or even use another component
  • HTTP friendly, it gives you total control over the requests passing between browser and server
  • Testability of MVC makes it simple to unit test the logic that is specific to a page, by testing controller methods
Cons 

It does not really have many cons compared to its pros:
  • The lake of drag and drop component in WebForms, despite that JQuery and other JavaScipt library overcome this problem
  • It's not as easy as WebForms, you should understand the role of each component individually and all of them together.

Nov 16, 2012

Interface class

Sometimes it is simple and helpful to define a class that does nothing but defines a standardised interface that can be used by other classes to make sure the implementation follows a standard set of input and output paramaters. Also this approach results in faster code runs and more maintainable code.

The interface class can only be approached by using a pointer to the virtual table that exposes the methods in the interface. Interface does not come by itself, it usually comes with an inherited class that implements the exposed method in the interface. Such a class that implements the interface exposed methods is often called a co-class.

OOPS Concept with Real-world example

Introduction

OOP is Nothing but Object Oriented Programming.According to Wikipedia,  Object-oriented programming (OOP) is a programming paradigm that uses "objects" and their interactions to design applications and computer programs.

Asp.Net Tutorial (PART-15)

Displaying Information

The ASP.NET Framework includes two controls you can use to display text in a page: the Label control and the Literal control. Whereas the Literal control simply displays text, the Label control supports several additional formatting properties.

Nov 15, 2012

Web Server Controls vs. HTML Server Controls

One of the first possible points of confusion when learning to build web forms is "what is the difference between a Web Server Control and an HTML Server Control?" This probably stems largely from the fact that most of the Web and HTML Server Controls don’t differ much – for example, the Label Web Server Control operates almost identically to the Label HTML Server Control. However, there are some subtle differences between the two.

Nov 14, 2012

Adding Code to the Event Handler (PART-14)

Adding code to the event handler is, well, exactly as you would expect it to be. Place the cursor in the space between Protected Sub Button1_Click(…) and End Sub and type the appropriate code in. For

now, all the code will do is change the text of the label (Label1) to, you guessed it, "Hello world!". Type in the following code, and pause after you type the period:

Nov 11, 2012

.Net C# How to dynamically add controls to a form

Dynamically Adding Controls to a Windows Form

I have a project right now who’s requirements are to dynamically create sections on a form, dynamically create items in those sections (checkboxes, text boxes, etc), and store the values entered in those boxes in a database.

Now this is no small task, but it had me thinking. It’s been a while since I wrote something that used dynamic controls. Since I’m writing the code anyway I thought I would share the technical details as to how you too can create your own controls on the fly, and hook up the events, and read the data. So many web demo’s seem to show the first and miss the next two (which would be the same as missing the point entirely..)

Nov 10, 2012

Create Html Table Dynamically

The following code dynamically creates a table with five rows and four cells per
row, sets their colors and text, and shows all this on the page. The interesting detail is that no control tags are declared in the .aspx file. Instead, everything is generated programmatically.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class DynamicTable : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HtmlTable table1 = new HtmlTable();

        // Set the table's formatting-related properties.
        table1.Border = 1;
        table1.CellPadding = 0;
        table1.CellSpacing = 0;
        table1.BorderColor = "red";

        // Start adding content to the table.
        HtmlTableRow row;
        HtmlTableCell cell;
        for (int i = 1; i <= 3; i++)
        {
            // Create a new row and set its background color.
            row = new HtmlTableRow();
            row.BgColor = (i % 2 == 0 ? "lightgreen" : "lightgray");
            for (int j = 1; j <= 5; j++)
            {
                // Create a cell and set its text.
                cell = new HtmlTableCell();
                cell.InnerHtml = "Row: " + i.ToString() + "<br />Cell: " + j.ToString();
                // Add the cell to the current row.
                row.Cells.Add(cell);
            }

            // Add the row to the table.
            table1.Rows.Add(row);
        }

        // Add the table to the page.
        this.Controls.Add(table1);
    }
}

KEYWORDS,IDENTIFIERS and DATA TYPES in C#.Net

Introduction

KEYWORDS :
Keywords are the words which are language specific. A keyword is an essential part of a language definition. These words cannot be used as identifiers. Identifiers are nothing but names given to various entities used in a program. The examples of keywords are event, byte, break, using, class..etc

IDENTIFIERS :
Identifiers are program-defined tokens. Identifiers are names of various program elements like classes, methods, variables, namespaces, interfaces...etc. in the code that uniquely identify an element. Now let us see what these entities are.

Linq To Sql Demo

Web.Config

<appSettings>
    <add key="constr" value="Data Source = machine/server;
    Initial Catalog=DatabaseName;User ID=userid; password=password"/>
  </appSettings>
    <connectionStrings>
  <add name="TradeplusConnectionString" connectionString="Data Source = machine/server;Initial Catalog=DatabaseName;User ID=userid; password=password"
       providerName="System.Data.SqlClient" />
 </connectionStrings>

UpdateProgress in Asp.Net

One of the problems with Ajax, is the fact that since it's asynchronus and in the background, the browser will not show you any status. With fast servers and fast methods, this is not a big problem, but whenever you have a method which takes up a bit of time, the user is very likely to get impatient.

Fortunately, ASP.NET AJAX solves this problem for us as well, with a nice control called UpdateProgress. It will use your own template to show that an asynchronus method is working. Have a look at the following example, which will show the control in action. It will be explained afterwards.

Nov 9, 2012

Create an override for a datagrid within a user control(WPF)

The XAML

<UserControl>
 <Grid>
        <toolkit:DataGrid  ItemsSource="{Binding Source={StaticResource DocumentsVS}}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"
                FontSize="16" Name="_dgDocuments" Style="{StaticResource EklektosDataGridStyle}" . . . >
</UserControl>

OR

<local:MyDataGrid x:Name="dataGrid"/>

In case you want to override the OnCreateAutomationPeer of your dataGrid, you have to subclass the dataGrid -

public class MyDataGrid : DataGrid
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return null;
    }
}

And in constructor of your UserControl -

public CDocumentChecklistView()
{
    InitializeComponent();
    AutomationPeer a = UIElementAutomationPeer.CreatePeerForElement(dataGrid);
}

Nov 8, 2012

IList Generic Interface

IList Generic Interface represents a collection of objects that can be individually accessed by index.

This example demonstrates how to use IList Generic Interface to store data.
IList Generic Interface represents a collection of objects that can be individually accessed by index.
First, you will need to import the System.Collections.Generic namespace.
using System.Collections.Generic;

MenuStrip in C#

The MenuStrip class is the foundation of menus functionality in Windows Forms. If you have worked with menus in .NET 1.0 and 2.0, you must be familiar with the MainMenu control. In .NET 3.5 and 4.0, the MainMenu control is replaced with the MenuStrip control.

Creating a MenuStrip

We can create a MenuStrip control using a Forms designer at design-time or using the MenuStrip class in code at run-time or dynamically.

To create a MenuStrip control at design-time, you simply drag and drop a MenuStrip control from Toolbox to a Form in Visual Studio. After you drag and drop a MenuStrip on a Form, the MenuStrip1 is added to the Form and looks like Figure 1. Once a MenuStrip is on the Form, you can add menu items and set its properties and events.

Basic differences between Oracle and SQL Server

most obvious differences are:

  • The FIRST biggest difference: Transaction control. In Oracle EVERYTHING is a transaction and it is not permanent until you COMMIT. In SQL Server, there is (by default) no transaction control. An error half way through a stored procedure WILL NOT ROLLBACK the DDL in previous steps.

Obviously, if you wrap the TSQL DML in BEGIN TRANSACTION and COMMIT then it will roll back but this is rare in SQL Server code I've seen.

  • The SECOND biggest difference: MVCC. In SQL Server and Oracle is different. SQL Server will allow dirty reads, and writes can block reads in MS SQL (Again, it's configurable but the default in SQL Server is for performance and not read consistency, unlike Oracle where read consistency is default and unbendable.

Also consider:

  • When you setup an Oracle server, you tend to have one database with many "users/schemas", and tablespaces that are shared by all your users. SQL Server has separate databases that do not share disk files.
  • SQL Server uses "logins" to give you access to the SQL Server instance and each database has "users" that map to a login to get individual access to the tables and views etc.
  • Typically, all the objects in a database are owned by dbo.
  • TSQL is similar to PL/SQL, but (in my opinion) less powerful. You may need to simplify your SQL to get it to work as well as you'd expect in Oracle.
  • The SQL Server Management Studio (2008 SP1) is fantastic!
  • If you like Oracle, all the "getting under the hood" and "explain plan optimisation" then this training and experience will work well for you against guy's who just code straight SQL Server TSQL and expect the server to perform fast by magic.
  • SQL Server does not have packages. This might start off as a bonus (PL/SQL packages can be a PITA) but eventually you'll start to get a big nest of similarly named stored procedures in the database and you'll wish there was a way you could organise and group then them better.

Dynamically populate drop-down that is part of form array

I will show you the HTML code, this code consist of two dropdownlist / combo box (two <select> element) with the second <select> element disabled and will be enabled if we choose something from the first <select> element. Here the HTML code (dnmddl.htm):

Nov 7, 2012

DockPanel in Silverlight

If you have used docking Windows in previous versions of .NET, the DockPanel is used to provide that functionality in WPF and Silverlight. The DockPanel is not a part of Silverlight 2. It is a part of Silverlight Toolkit but I am sure it will be a part of the next version of Silverlight.

The DockPanel control is a layout control that acts as a container for child controls. The DockPanel allows child controls to dock in left, right, top, or bottom sides of the panel.

Using Settings in C#

Introduction

The .NET Framework 2.0 allows you to create and access values that are persisted between application execution sessions. These values are called settings. Settings can represent user preferences, or valuable information the application needs to use. For example, you might create a series of settings that store user preferences for the color scheme of an application. Or you might store the connection string that specifies a database that your application uses. Settings allow you to both persist information that is critical to the application outside of the code, and to create profiles that store the preferences of individual users.

While Visual Basic 2005 has provided an easily discoverable mechanism for accessing settings using the My namespace, there is no analogous namespace in Visual C# 2005, and thus settings are somewhat more difficult to access. Nonetheless, C# users can still use settings by accessing the Properties namespace. In the course of this article, you will learn the difference between application and user settings, how to create new settings at design time, how to access settings at run time, and even how to incorporate multiple sets of settings into your application.

How To Keep ASP.NET ViewState On The Server

During recent few engagements with my customers I've noticed  VIewState is extensively [unintentionally] used. ViewState is on by default. The result is heavy weight Html that round trips on the network. This causes slow response time and high network utilization that affects another applications using the same network.

How to remove ViewState from the network completely while taking an advantage if its functionality at same time?

Introduction to Styles in WPF

Introduction

First of all you have to create a new WPF  Project  for that you can do as following.



Nov 5, 2012

How to create a countdown timer application using C# and WinForms

In this tutorial I will explain how to create a countdown application in C#. For this application I did not declare any additional namespaces.

StatusBar in c# Windows Application

StatusBar Example

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace StatusBarExample
{
  /// <summary>
  /// Summary description for StatusBarExample.
  /// </summary>
  public class StatusBarExample : System.Windows.Forms.Form
  {
    internal System.Windows.Forms.StatusBar statusBar;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public StatusBarExample()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if (components != null)
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.statusBar = new System.Windows.Forms.StatusBar();
      this.SuspendLayout();
      //
      // statusBar
      //
      this.statusBar.Location = new System.Drawing.Point(0, 138);
      this.statusBar.Name = "statusBar";
      this.statusBar.ShowPanels = true;
      this.statusBar.Size = new System.Drawing.Size(292, 24);
      this.statusBar.SizingGrip = false;
      this.statusBar.TabIndex = 1;
      //
      // StatusBarExample
      //
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
      this.ClientSize = new System.Drawing.Size(292, 162);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.statusBar});
      this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.Name = "StatusBarExample";
      this.Text = "StatusBar Example";
      this.Load += new System.EventHandler(this.StatusBarExample_Load);
      this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
      Application.Run(new StatusBarExample());
    }

    private void StatusBarExample_Load(object sender, System.EventArgs e)
    {
      StatusBarPanel pnlStatus = new StatusBarPanel();
      pnlStatus.Text = "Ready";
      pnlStatus.Icon = new Icon(Application.StartupPath + "\\active.ico");
      pnlStatus.AutoSize = StatusBarPanelAutoSize.Contents;

      StatusBarPanel pnlConnection = new StatusBarPanel();
      pnlConnection.Text = "Connected to " + "localhost";
      pnlConnection.AutoSize = StatusBarPanelAutoSize.Spring;

      statusBar.Panels.Add(pnlStatus);
      statusBar.Panels.Add(pnlConnection);

    }
  }
}

Related Posts Plugin for WordPress, Blogger...