Skip to main content

Posts

Get a Random Row From a SQL Databse with ASP 4.0 and C#

This tutorial will demonstrate how to get a random row from your SQL database using ASP.NET 4.0 and C#.  Selecting random rows from a database can be useful for many different purposes such as displaying random images, quotes, products, or anything else that your database may contain. In this example we will choose a random number from a database. Adding the Default.aspx Page At this point in the tutorial I have created a new ASP.NET Empty Web Site. What we need to do first is add in a blank Web Form that we will use to test our SQL query and ensure that we are getting the correct results. To do this: Right click the project in your Solution Explorer. Select Add New Item... Select a Web Form and name it Default.aspx. Click Add. We migrated our web sites to  Server Intellect  over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With  Server Intell...

Generating Random Number and String in C#

The Random class defined in the .NET Framework class library provides functionality to generate random numbers. The Random class constructors have two overloaded forms. It takes either no value or it takes a seed value. The Random class has three public methods - Next, NextBytes, and NextDouble. The Next method returns a random number, NextBytes returns an array of bytes filled with random numbers, and NextDouble returns a random number between 0.0 and 1.0. The Next method has three overloaded forms and allows you to set the minimum and maximum range of the random number. The following code returns a random number: int  num = random.Next(); The following code returns a random number less than 1000. int  num = random.Next(1000); The following code returns a random number between min and max: private   int  RandomNumber( int  min,  int  max) { Random random =  new  Random(); return  random.Next(min, max); ...

Common Regular Expressions

Common Regular Expressions Some common regular expressions are shown in Table 1. Table  Common Regular Expressions Field Expression Format Samples Description Name ^[a-zA-Z''-'\s]{1,40}$ John Doe O'Dell Validates a name. Allows up to 40 uppercase and lowercase characters and a few special characters that are common to some names. You can modify this list. Social Security Number ^\d{3}-\d{2}-\d{4}$ 111-11-1111 Validates the format, type, and length of the supplied input field. The input must consist of 3 numeric characters followed by a dash, then 2 numeric characters followed by a dash, and then 4 numeric characters. Phone Number ^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$ (425) 555-0123 425-555-0123 425 555 0123 1-425-555-0123 Validates a U.S. phone number. It must consist of 3 numeric characters, optionally enclosed in parentheses, followed by a set of 3 numeric characters and then a set of 4 numeric characters. E-mail ^(?("")(...

Count characters left on keypress using javascript

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title>Untitled Page</title>     <script type="text/javascript" language="javascript">      function CountTxtLeft(StrTxt, txtCount, totaltxt) {     if (StrTxt.value.length > totaltxt)      {         StrTxt.value = StrTxt.value.substring(0, totaltxt);         }     else     {         txtCount.value ='Total characters left :' + (totaltxt - StrTxt.value.length);         } }     </script> </head> <body...

Ten more CSS tricks you may not know

1. Block vs. inline level elements Nearly all  HTML  elements are either block or inline elements. The  characteristics of block elements  include: Always begin on a new line Height, line-height and top and bottom margins can be manipulated Width defaults to 100% of their containing element, unless a width is specified Examples of block elements include  <div> ,  <p> ,  <h1> ,  <form> ,  <ul>  and  <li> . Inline elements  on the other hand have the  opposite characteristics : Begin on the same line Height, line-height and top and bottom margins can't be changed Width is as long as the text/image and can't be manipulated Examples of inline elements include  <span> ,  <a> ,  <label> ,  <input> ,  <img> ,  <strong>  and  <em> . To change an element's status you can use  display: inline  or...