The input element with type attribute value equal to "email" represents a control to accepts values in an e-mail address format. It doesn't check or validates empty or empty value.

Supported in:
Works in Chrome
Not in Firefox, IE

  
  
  
  


Sample Result:









Code Reference:
Najeeb W. Najeeb


To exit the foreach earlier than it suppose to be we have to use the break statement. By using the break statement, it terminates the closest enclosing loop or switch statement.

Please see the example below. The statements below is an example of a search algorithm where the loop terminates as soon as it found the search item on the list.

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

namespace TestSolution
{
    public partial class ForeachBreak : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //creates list of string data
            List lst = new List();
            lst.Add("anna");
            lst.Add("jun");
            lst.Add("sam");
            lst.Add("leila");

            //set search item to search to the list
            string searchItem = "jun";
            
            //flag to know that the item been seached exist or not
            bool isFound = false;

            foreach (string s in lst)
            {
                if (s.Equals(searchItem))
                {
                    isFound = true;
                    break; 
                }
            }

            //show the result
            Response.Write(isFound);

        }
    }
}

To change the value or content of the div tag, use the .html() property.

Syntax:
[DivID].html([value]);

Where [DivID] is the id of the div and [value] is the value or content you want to put on the div. The [value] accepts html tag.

In my example below, i use drop-down menu to dynamically change the value of the div tag.
     
    
    
    What is your favorite color?
    
        
        Blue
        Red
        Violet
        White
    
    

    

    Your favorite color is:
    
[blank]
Result:










L.
Sending mail in C# is very straight forward. Follow the following steps:

1. Set-up SMTP E-mail Settings. You can either set-up under ASP.NET Configuration or manually set-up under web.config.

    Option 1: ASP.NET Configuration
          a. Under Menu, go to "Project" and click on "ASP.NET Configuration". Click the "Application" tab, and then click the "Configuration SMTP e-mail settings".




          b. Set-up email settings. Add SMTP Settings depending on your mail server. the example below uses google smtp server for example purpose only.







    Option 2: Manual Mail setting at web.config
          a. Add the following tag under inside configuration tag of the web.config file.
  
    
      
        
      
    
  
2. Add code statement. Add the following code statement on the code behind. The statement below sends message to email.

using System.Net.Mail;
using System.IO;

        protected void Page_Load(object sender, EventArgs e)
        {
            SendEmail();
        }

        private void SendEmail()
        { 
            MailMessage message = new MailMessage();
            message.From = new MailAddress("usernameFrom@gmail.com", "Name");
            message.To.Add("usernameTo@gmail.com");
            message.Subject = "Test Subject";

            //if you want the message to show as HTML format
            message.IsBodyHtml = true;

            message.Body = "Your email message here.";

            var client = new SmtpClient("smtp.gmail.com", 587);
            //make sure its the same with SMTP Settings
            client.Credentials = new System.Net.NetworkCredential("username@gmail.com", "MyPasswordHere");
            client.Send(message);
        }

3. Test and check sent email.


L.
Regular Expression:
[0-9]*

The regular expression above validates numbers at any length.

Used in ASP.NET Regular Expression Validator:
*
                    Total Amount Paid
                


L.
Format specifiers:
y (year)
M (month)
d (day)
h (hour 12)
H (hour 24)
m (minute)
s (second)
f (second fraction)
F (second fraction, trailing zeroes are trimmed)
t (P.M or A.M)
z(time zone)

C# Example:
//Create DateTime value
DateTime currectDateTime = DateTime.Now;

Response.Write(String.Format("#1 {0:y yy yyy yyyy}", currectDateTime));




The change event is fired when as element change its value. This is commonly use to checkboxes, radio buttons, drop down and the likes. Some element fired immediately but others does when you loses focus.

Here is the sample HTML Code using drop down, I have it on the ASP.NET Solution. It shows the whole code inside the <body> tag to get full idea of how it is coded in one page.


In [Box1], Script Reference is set. Before you can use a jQuery function, you have to have a script reference to a jQuery library to use. On my example above, I have my jQuery library saved on the project itself under Scripts folder.

In [Box2], the javascript code is placed. In my example above, I show the selected value to the a TextBox. In ASP.NET, the ID of the component changes as you run the application, to make sure that we are calling the same ID of the object we use the following code <%=NameOfTheField.ClientID %>.

[Box3] has the HTML tag.

L.
On the code behind, use intelliSense to show available page's events to override.

Type the following to enable intelliSense;

protected override ....

you see on the image below that list of available events will show as you type. Select the event you want to override and it will auto fill-in the event format code.



After you select an event, code similar to image below (depending on the method you selected) will show. Enter the additional code after the baseOnInit(e);, as shown below. 


L.
Syntax: 
<result> = <condition> ? <true result> : <false result>;

Example:
string result = 5 > 10 ? "5 is greater than 10." : "5 is not greater than 10.";
Response.Write(result);

Result:
5 is not greater than 10.


L.
Regular Expression:
^((4\d{3})|(5[1-5]\d{2})|(6011)|(34\d{1})|(37\d{1}))-?\d{4}-?\d{4}-?\d{4}|3[4,7][\d\s-]{15}$

The regular expression above validates all credit card number such as Visa, Master Card, American Express and Discovery.

Used in ASP.NET Regular Expression Validator:


L.
As we do update our application, there is no doubt that we also need to make some changes on our database structure. What if we already set-up the LINQ to SQL Classes, how will you keep these two (SQL Database and LINQ Layout Diagram) sync together?

Unfortunately, updating the database structure from the SQL Management Studio doesn't guarantee that your project's LINQ Layout Diagram will update too. These two are separate entity that you need to do a little work to keep them in sync together.

Here are some ways:

1.  From the Visual Studio - delete, drag and drop.
     a. On the Visual Studio, open the LINQ Layout Diagram, this is the file with the .dbml extension.
     b. Select the table that you want to update, then delete by doing right click then "delete" or you can simply click the delete key on your keyboard.
     c. Open the Server Explorer, select the table you want to update then drag to the LINQ Layout Diagram.
     d. Notice that fields are now updated and the relationship are keep in place.

2. Make the change directly in the properties - works on simple changes per field.
     a. On the Visual Studio, open the LINQ Layout Diagram, this is the file with the .dbml extension.
     b. Update the field
          1. Select the field that you want to change and open the Properties pane.
          2. On the Properties pane, make the necessary changes you want. Example, if you want to change the size of it's data type as NVarChar type from 50 to 200, do so by replacing the NVarChar(50) to NVarChar(200) under the "Server Data Type".
     c. Add field
          1. Right click on the table where you want to add field then select "Add" -> "Property".
          2. Notice that new field is added, you can now set-up of the properties of that new item.
     d. Delete field
          1. You can simply delete a property by doing right click "Delete" on the property you want to delete or you can simply click the delete key on your keyboard.

3. You can use a Third Party Software that does the auto sync. 
Examples is the Perpetuum Software and the likes.


L.

Error Message:
The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 


Solution:
Add "System.Data.Linq" reference to the project,

Steps to add reference:
1. Right click on the project that has an error.
2. Click on "Add Reference.."
3. Under ".NET" tab, select the "System.Data.Linq" component and click "OK".
4. Expand the References of the project and should see the System.Data.Linq has been added.


L.

LINQ (Language Inegrated Query), pronounced as "link" is a Microsoft .NET components that adds data querying capabilities to .NET languages (VB/C#). 1

 There are different ways to set-up your application to be LINQ-SQL enabled. The one that i'll be showing you is very straight forward, using the LINQ to SQL Classes.

Let's assumed you already have your database information and you have access right. You can try by checking the Data Connections of the Server Explorer on Visual Studio 2010 or Database Explorer for the older versions. Your should be able to see your database as connected.

Here are the steps to integrate LINQ to SQL:
1. Expand the Solution Explorer

2. Select the Project where you want to add the LINQ to SQL Classes, then right click. Click "Add" --> "New Item.."

3. On the new window, expand the "Visual C#" (or Visual Basic if your language is Visual Basic), click on the "Data". Then on the center portion, select "LINQ to SQL Classes".

4. At the bottom part of that window, replace the name with your desired name. Leave the ".dbml" extension. Click "Add".  Notice that new item has been added to your project.

5. Double click new added file to open the "LINQ to SQL Classes" Designer. It is the file with the ".dbml" file extension.

6. Open the Server Explorer window, you should see your database when you expand Data Connections.

7. Expand the "Tables" of your database and then select then drag and drop the table names you want to use to the designer page or window. You now see the table with the fields and their relationship if there is any.

8. Your LINQ project is now linked to SQL.

To make a LINQ statement, use the "DataContent" of the System.Data.Linq. Unfortunately, it is not covered in this article. Hope to post one that discuss about that into much details.

Reference:
 http://en.wikipedia.org/wiki/LINQ


L.
ASP.NET 2.0 and later versions provides easy to use Server controls to create secure Login pages. By default,  as you create a new project, new and separate MS SQL database is created (aspnetdb.mdf) under the App_Data folder. In real life scenario, databases are located on a separate server where different users connects. Of course, we would like to add the Membership files on that same database.

In order to incorporate Membership files to an existing database, follow the following steps:

Prior to this steps, we assumed that you have the information of the existing database and have Administative rights.

1. Back up MS SQL Database (existing and aspnetdb).

2. Execute the executable file below:
C:\Windows\Microsoft.NET\Framework\v2.(something)\aspnet_regsql.exe

3. "ASP.NET SQL Server Setup Wizard" will pop-up. Click "Next".

4. Select the first option. (Second option enables you to remove all Membereship files from the existing database). Click "Next".

5. Type the Database Server Name, and select the database you want to add the Membership files. Click "Next".

6. Check the existing database, you now can see all the Membership files (tables) you need. Basically, all the tables you have on the aspnetdb.mdf.

7. Now, as our last step, we need to change a little few things on the web.config of the project. "YourConnectionStringName" is the name of you connection string under the <connectionstring> node.

Notice the sample code below:

Under <system.web>, search for roleManager node;
Before:
    <roleManager enabled="false">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="YourConnectionStringName" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>


After:
    <roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
      <providers>
        <add connectionStringName="YourConnectionStringName"
             name="CustomizedRoleProvider"
             type="System.Web.Security.SqlRoleProvider" />
      </providers>
    </roleManager>


Under <system.web>, search for membership node;
Before:
    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="YourConnectionStringName"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>


After:
    <membership defaultProvider="CustomizedMembershipProvider">
      <providers>
        <add name="CustomizedMembershipProvider"
             type="System.Web.Security.SqlMembershipProvider"
             connectionStringName="YourConnectionStringName"/>
      </providers>
    </membership>


8. Run and test to make sure that the Membership provider is working properly. Open the "ASP.NET Web Site Administration Tool" on your Visual Studio. Go to menu, select "Project" and then click the "ASP.NET Configuration". On this window, you should be able to view or manage your user in information.


L.
As default, the line number of the source page is not showing. In order to display the line numbers, follow the steps below.

On your Visual Studio menu, go to "Tools" --> "Options..", new window will pop-up.
On the left side, expand the "Text Editor" then click on "All Languages".
On the right side, under Display, check the "Line numbers" then click OK.

Viola! As you noticed, line numbers on the left side of the source page is now showing.


L.
Welcome to Programming 101!

One thing that I love to do aside of cooking is programming. Well, I am not as genius as my other colleagues and friends but I do enjoy doing programming. It's like I am in a secret place where me and computer communicate in our own language. Literally, my own language.. Because even my co-programmer friends can't understand what I am doing. :D I remember during college days when my friends and classmates thinks I am weird, staying hours in front of the computer doing some codes rather than to mingle with others. Back then, I am one of the top student in programming in our class.. And I am proud! But because of my timid personality, I didn't get much exposure but I am happy and contented of what i've become.

Ok.. Enough of me, let's talk about what I am thinking about this blog.

In this blog, I will be focusing about programming stuff. I am a professional web application developer so you would notice more of web stuff but i'll try to share some other items specially the hot items in technology today. I hope that people who read (if there is any :D) will do participates by posting comments and questions, suggestions are also welcome.

Lastly, please bare with my grammar. ^_^ (i don't have a budget for an editor)

Ok.. See you on my next post.


L.