-->

Saturday, June 29, 2013

How to use ValidationSummary Control in ASP.NET

Introduction
The ValidationSummary control collects all the validation control error message (known as summary) and displays it collectively on the screen . The display of the summary , which can be a list , a bulleted list , or a single paragraph , can be set by using the DisplayMode property . You can also specify whether the summary should be displayed in the web page or in a message box by setting the ShowSummary and ShowMessageBox properties respectively . The validationSummary control exists within the System.Web.UI.WebControls namespace.
Public Properties of  ValidationSummary Class

DisplayMode : Obtains or set the display mode of the ValidationSummary Control.

EnableClientScript : Obtains or set a value indicating whether the ValidationSummary  control updates itself using the client-side script.

ForeColor : Obtains or sets the foreground color of the control.

HeaderText : Obtains or sets the header text displayed at the top of the summary.

ShowMessageBox : Obtains or sets a value showing whether the validation summary is displayed in a message box.

ShowSummary : Obtains or sets a value showing whether the validation summary is displayed in line.

ValidationGroup : Obtains or set the group of controls for which the ValidationSummary object displays validation message.

Example :

<p>
<h2>Login for security</h2></p>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" BackColor="#CCCC00" BorderColor="Black" BorderStyle="Solid" BorderWidth="4px" />
<p>
Enter member username :&nbsp;
<asp:TextBox ID="usrtxt" runat="server" Width="182px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="usrtxt" ErrorMessage="Enter Username" ForeColor="Maroon">*</asp:RequiredFieldValidator>
</p>
<p>
Enter&nbsp; member password : <asp:TextBox ID="pwd" runat="server" TextMode="Password" Width="182px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="usrtxt" ErrorMessage="Enter password" ForeColor="Maroon">*</asp:RequiredFieldValidator>
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="Member Login" OnClick="Button1_Click" />
</p>
<p>
&nbsp;</p>


Output
validationSummary




Friday, June 28, 2013

How to use RegularExpressionValidator Control in ASP.NET

Introduction
Regular expression are used to check whether or not the text matches a certain pattern . The RegularExpressionValidator control validates whether the value in the input control (text box) matches the format specified by the regular expression , such as a US telephone number or a date format . The RegularExpressionValidator control exists within the System.Web.UI.WebControls namespace.
In general , regular expression are made up of text within an embedded code listing that starts with a backslash (\) as well as other control code listing . The following is an example:
\b[A-Za-z]+\b
The code for a word boundary (where a word ends or starts ) is \b and a character class is a set of characters surrounded by [ and ] . This allows you to specify what character you want to accept . So , this regular expression matches a word consisting of uppercase or lowercase letters only. The + sign stands for one or more of , so we matching one or more uppercase and / or lowercase letters here.

for example , the regular expression to determine if the text matches a valid e-mail address is :
\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
Here , \w stands for a word character (such as letters , underscores, and the rest) and * means zero or more of .
Public Property of the RegularExpressionValidator Class

ValidationExpression : Obtains or sets the regular expressions that you want to match data against for validation.

Example


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>



Enter your Email Address:
 
 
<asp:TextBox ID="Emailtxt" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="Emailtxt" Display="Dynamic" ForeColor="Maroon">Email format incorrect</asp:RegularExpressionValidator>
&nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Emailtxt" Display="Dynamic" ErrorMessage="Fill must" ForeColor="Maroon"></asp:RequiredFieldValidator>
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
<br />
</div>
</form>
</body>
</html>
OutPut
emialvalidator

Thursday, June 27, 2013

How to use RequiredFieldValidator Control in ASP.NET

Introduction

The Required FieldValidator control is the simplest control , and is used to ensure that the user has entered the data into the input control, such as TextBox to which it is bound. For example , if you are entering data, for buying a T-shirt , in an input control , it is necessary to enter the size of the T-Shirt that you want to buy. If you do not enter a value , the validation control displays an error message .

Public property of the RequiredFieldValidator Class

initialValue : Handles the initial value of the associated input control.

Example



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="requiredfield.aspx.cs" Inherits="requiredfield" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>






UserName :
 
 
<asp:TextBox ID="usrtxt" runat="server"></asp:TextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="usrtxt" ForeColor="Maroon">Field is required</asp:RequiredFieldValidator>

<br />

<asp:Button ID="Button1" runat="server" Text="Submit" />





 
 
</div>

</form>

</body>

</html>

 
Output
validator
 

Visual studio 2013 ,start with a familiar environment

In visual studio 2013 , Select your general Development setting using dropdown menu Also select theme option . There are three theme option Blue, Dark and light.

Visual Studio 2013 Start-Up Screen:

 
New in Microsoft platform
  • Windows
  • Windows Azure
  • ASP.NET vNext and Web
  • Windows Phone
  • Microsoft Office
  • Share Point Development
Features
  • Database Table Appear in server explorer without refresh
Download
 

 

 
  •  




Wednesday, June 26, 2013

Cut, Copy and paste operations in windows forms

Introduction

It is impossible for one, specially a Programmer, to imagine his/her life without editing. Editing operations (Cut/Copy and paste etc.) are performed using clipboard, so these are also called Clipboard operation.
Invention

Larry Tesler, who invented Cut/Copy and paste in 1973. He is a computer scientist, working in the field of human-computer interaction. Tesler has worked at Xerox PARC, Apple Computer, Amazon.com and Yahoo! We can find out more about LarryTesler.


In this article I will show how to perform these operations with our own code. As we are just doing editing operations, it doesn't matter which control we are using. Here I am using two textboxes to perform this operation. I created a simple window form with a menu strip and two textboxes. In the menu strip all the operations are added in Edit menu item as shown in below screenshot.



Generate the click event of above three menu items. 
Copy

We are going to copy the selected text of textbox, so we use SelectedText property of textbox. To copy the data in clipboard there is a method in Clipboard class i.e. SetData(), which will clear the clipboard and then add new data in specified format to clipboard.

private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
      TextBox txtBox = this.ActiveControl as TextBox;
      if (txtBox.SelectedText != string.Empty)
         Clipboard.SetData(DataFormats.Text, txtBox.SelectedText);
Cut

Actually, cut operation is a combination of copying and removing that text from that location. So we will copy the text and empty that string after that.

private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
    TextBox txtBox = this.ActiveControl as TextBox;
    if (txtBox.SelectedText != string.Empty)
       Clipboard.SetData(DataFormats.Text, txtBox.SelectedText);
    txtBox.SelectedText = string.Empty;
Paste


To insert clipboard data to current location is called paste. We can perform a paste operation multiple times with a single clipboard data. To paste the data from clipboard there is a method in Clipboard class i.e. GetText(). First we get actual position of cursor in the textbox and then insert the data to that position using Insert() method as in above code.

private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
    int position = ((TextBox)this.ActiveControl).SelectionStart;
    this.ActiveControl.Text = this.ActiveControl.Text.Insert(position, Clipboard.GetText());
}

Insert() is a method of string class, which return a string in which a specified string is inserted at a specified position. So that is how we perform editing operations with our own code. The same procedure can be used to perform these operation in other controls of windows forms.

Download source.
© Copyright 2013 Computer Programming | All Right Reserved