Archives
-
Treeview Datasource for Linq to Entities versus a SQL Command in Code-Behind versus Code-In-Front
In this example, I'll show the differences between populating a Treeview using Linq to Entities, versus a SQL Command in Code-Behind using a function, versus Code-In-Front using a SelectCommand.
-
ADO.NET Linq to Entities versus Linq to SQL
I recently did a project using LINQ to SQL. I decided to convert it to the ADO.NET Linq to Entities model instead. It was fairly easy to convert with a few gotchas. I will list the changes here:
-
The new CPU Laptop MonKey (monitor+keyboard)
Face it, laptops are flimsey. We have 5. They constantly have problems and 3 recently broke down. Just in time for Christmas.
-
ADO.NET Entities Tutorials
I have been working with the ADO.NET Entities Data Model for ORM and I am very impressed. I'd been working with Data Sets and Table Adapters, so was excited about diving into the new release of ADO.NET Entities Data Model.
-
Property: Visual Studio Tip
In Visual Studio, when you create a new Property, you're likely aware that as you type, intellisense will allow you to type the property name and type and upon hitting enter, it prepopulates the Property as below:
-
Need a New Technology? Part 2: More Training Resources
I received such a positive response from my post on Laid off? Need a new technology? Free Microsoft Training and Education that I decided to follow up with this brief post.
-
SQL Server: Copying a Database, including Constraints, Keys, Indexes...
In SQL Server, if you wish to copy the structure of an entire database, including the Constraints, Keys, Indexes, etc., don't use the Import option, as it does not include the constraints, keys, indexes, etc. Instead, within SQL Server Management Studio, right click a database, select Tasks, then "Generate Scripts."
-
Anti-XSS Library for Security and Prevention of Hackers
I just attended the online event, Security Sidebars and Hacker Tricks! (Level 200). Mike Benkovich of BenkoTips fame, shared with us how hackers can send an email taking a user to your site, but instead, the link inserts an iframe into your page that takes the user to their site instead, where they get the user's credit card info, etc. He also showed many other hacker tricks, including changing the price of an item on your shopping cart page, so they can purchase mass quantities of an item at $1, that should cost $300.
-
Laid off? Need a new technology? Free Microsoft Training and Education
Are you a developer who's been laid off? Have you been faced with checking the job boards to find your skills are nearly obsolete and there's nothing available? If you have the ability to program in an old technology, you can learn a new one. It may seem daunting at first, because you don't have the money to invest in new tools and training classes, but I assure you, you can learn ASP.NET and find a vast amount of free help without spending a dime.
-
MailSettings for Remote Mail Server using SMTP Network Windows 2008 Web Server
Fixing the dreaded: Mail error: Syntax error in parameters or arguments. The server response was: 5.7.1 xx@xx.xx... Permission Denied
-
Membership Provider Connections to remote database in IIS7 Windows 2008 Web Server
I recently went through a nightmare with getting the Membership Provider Login and any other Membership Provider methods to work using Windows 2008 Web Server and IIS7 connecting to a remote SQL Server 2008 database.
-
New ASP.net Technologies, What to Do?
I have spent the last two weeks researching the latest ASP.net technologies and I have to admit, my mind's been swimming with the mass amount of new things out there to learn.
-
Telerik VB Dynamic Data Field Templates - DateTime Edit RadDatePicker
Telerik VB Dynamic Data Field Templates - DateTime Edit RadDatePicker:
-
Telerik VB Dynamic Data Field Templates - Foreign Key Edit RadComboBox
Here is a Telerik VB Dynamic Data Field Templates - Foreign Key Edit RadComboBox:
-
Telerik VB Dynamic Data Field Templates - Decimal Edit - RadNumericTextBox
Here is a customFieldTemplate for Decimal Edit using VB and Telerik controls - RadNumericTextBox :
-
Default Page - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 18
As we wrap up this series, we demonstrate how to add a databound grid control to our default page.
-
Dynamic Data Entities Examples and Tutorials
Here are some additional links to Dynamic Data, some using Entities. Again, people recommend not using LINQ to SQL, so using Entities seems the way to go... Thanks Rick for these suggestions. Couldn't find them by searching "Dynamic Data Entities Tutorial" on Google and if you don't know, you don't know until you know. So here you go!
-
Loading a Menu Programmatically based on Roles - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 17
As we continue our series, we'll look at programmatically loading a menu control.
-
Dynamic Data Entities Web Application
When you opened up your Visual Studio 2008, you may have seen the ASP.net News on the Start Page promoting Joe Stagner's Six New Videos on ASP.NET Dynamic Data.
-
SQL Server 2008 Web Edition
SQL Server 2008 Web Edition
-
Administration Page - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 16
To utilize our role provider and how to check roles, we have setup an Admin menu for our Admin user only.
-
Change Password Page - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 15
On our Change Password page, you'll notice how our change password control is wired up to use our custom membership provider:
<asp:ChangePassword ID="ChangePassword1" runat="server" SkinID="SSSCPskin1" MembershipProvider="Shiningstar.SSSMembershipProvider" -
Deploying the ASPNETDB.MDF to a Remote SQL Server Database
Topic: Using Publish to Provider to generate scripts to create/move/copy .MDF databases to your remote SQL Server database.
-
Visual Studio 2008 does not support SQL Server 2008 - SP1 Needed
I just purchased Visual Studio 2008 and SQL Server 2008 Web Edition and after setting up the database server, I tried to add a connection to my Visual studio 2008 project to obtain a remote connection and was given this error message:
-
Log Out Page - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 14
When the user clicks to Log Out, we'll call our own custom functions to kill the cookies, possibly make database changes, and return them to the Log In page.
The built-in Log Out functionality is overridden in this example so that we can have more control over our cookies and what events actually take place. -
Register Page - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 13
On our Registration page, we'll look at a few Regular Expressions. We'll use client side validation using the RequiredFieldValidator and also the RegularExpressionValidator. On server side, we'll again check our validations using our FormUtility class and some Regex regular expressions defined there.
-
Log In Page - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 12
On our Log In Page, we use a custom Remember Me checkbox instead of the checkbox included with the log in control. This way we can remove our log in cookie ourselves and do any database changes needed to log the user out.
-
Cookie Handler class - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 11
When we log in to the site, we optionally set a Remember Me cookie. This cookie is checked each time the Master Page is loaded, so that if the user is not logged in, they are auto-logged into the web site. Below are our cookie handling classes:
Our AppCookie.vb class is a generic handler for all cookies. Our SSSCookie.vb class is specifically for the current application. -
Our Master Page - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 10
Continuing our series, we look at our source code for our Master Page.
-
Our Custom RoleProvider Class - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 9
We continue our series by displaying our source code for our Custom RoleProvider class.
-
Customizing our MembershipProvider Class - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 8
In this series, we are now ready to customize our MembershipProvider class. We will use a custom Remember Me log in cookie.
-
Creating Our Custom MembershipUser Class - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 7
We are now ready to create our custom MembershipUser Class. First create a new class and add it to your ProviderClasses directory.
-
Adding Properties to Our Custom MembershipProvider Class - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 6
We now want to setup our properties for our custom SSSMembershipProvider class. In the below block of code, we will define variables to use in pulling the properties as setup within the web.config file.
-
Creating our Custom MembershipProvider Class - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 5
We want to now create our Custom Membership Provider class. Right click the ProviderClasses folder that you created in Step 1 and select "Add New Item."
-
Creating the Table Adapter Methods for GetUserByLogin, GetUserByUserName, and InsertUser
As we continue this series...
-
Creating The DataSet - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 3
In this series, we are now ready to add a new Data Set. In the Solution Explorer, right click the DataSets folder you setup in the App_Folder and select the "DataSet" template item. Give your new dataset a name. In my example, I name it "SSNetDataSet.xsd." Now select "Add."
-
Table Data Structure for this Tutorial - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 2
In Step 2 of this series, we learn how to:
-
Creating the Project and Folders - Creating a Custom Membership Provider and Membership User utilizing a Data Set Table Adapter - Step 1
In Step 1 of this series, we learn how to:
-
Creating a Custom Membership Provider and Membership User utilizing a DataSet Table Adapter - Introduction
In this article series, I provide a small web project in VB and zip file format to demonstrate how to write a Custom Membership Provider, Custom Membership User and Custom Roles using a DataSet and Table Adapters.
-
Product Review: List Transfer Control by Fluent
I needed a picklist implementation that involved a Listbox on the left and a Listbox on the right. With buttons in the middle to move items from the left to the right to the left, up and down within the Listbox, etc. I've programmed similar implementations, including my tree select demo. But my client had an existing control from Fluent Consulting.
The control is the List Transfer control. I was amazed at how easily I could implement the code.
In the code in front, simply register the control:
<%@ Register Assembly="Fluent.ListTransfer" Namespace="Fluent" TagPrefix="cc1" %>
<cc1:ListTransfer Runat="server" ID="lstClientTransferCodes" ListControlFrom="lstAvailable" ListControlTo="lstSelected" EnableClientSide="true" />
And in the code behind, simply add "onclick" attributes to the buttons:
ibtnMoveRight.Attributes.Add("onclick", Me.lstClientTransferCodes.ClientMoveSelected)
ibtnRightMoveDown.Attributes.Add("onclick", Me.lstClientTransferCodes.ClientMoveDownListControlTo)
ibtnRightMoveUp.Attributes.Add("onclick", Me.lstClientTransferCodes.ClientMoveUpListControlTo)
ibtnMoveLeft.Attributes.Add("onclick", Me.lstClientTransferCodes.ClientMoveBackSelected)
The rest, setting up the lists, binding the data, etc., didn't need to change at all.
All I had to do was add those 6 lines of code and boom, it was done!
I highly recommend this product!
I used this for client side transfer of data, but it also supports server side. View the demo here!
They describe the ListTransfer as "The ListTransfer control simplifies the transfer of ListItems between two ListControls. With this control you can easily create double listboxes or use several in combination."
I decided to see what other controls they have available, and noticed a Multi-LineTextboxValidator. This was of interest to me since I wrote an article in 2000 on the Javascript Dynamic Text Area Counter which I used extensively on my ASP Classic web sites. However, I'm all for upgrading to a control that can be easily plunked into my ASP.NET pages.
Here are the remainder of their controls: -
Section 9: C# and VB Project: Using our TableAdapters, DataTables and Intellisense
In our final Section 9 of this tutorial by Nannette Thacker, we learn how to use our TableAdapters within our code. We also look at how Intellisense makes it easy to set up your TableAdapter code.
-
Section 8: C# and VB Project: Using an OleDbDataReader to Retrieve Our Data
In Section 8 of this tutorial by Nannette Thacker, we take a look at adding a OleDbDataReader and the ExecuteReader method to retrieve data from an Excel Spreadsheet.
-
Section 7: C# and VB Project: TableAdapter Select and Insert Queries with Parameters
In Section 7 of this tutorial by Nannette Thacker, we learn how to create a select query statement in our table adapter and pass parameters to it. We learn how to create an insert query, use a "SELECT SCOPE_IDENTITY()" to retrieve the identity key value returned, and set our ExecuteMode to "Scalar" in our properties sheet.
-
Section 6: C# and VB Project: Data Access Layer DataSet TableAdapters
In Section 6 of this tutorial by Nannette Thacker, we learn how to retrieve data from an uploaded spreadsheet, and import it into a SQL Server database. We will create a Data Access Layer DataSet and some TableAdapters. We will learn how to add a data connection to our web.config. We will learn how to create SQL Statements in our TableAdapters and use the Query Builder.
-
Section 5: Bind the Excel Data to a GridView using an OleDbDataAdapter
In Section 5 of this tutorial by Nannette Thacker, we will learn how to create a connection to our Excel Spreadsheet using an OleDbConnection with a Microsoft.Jet.OLEDB Connection String. We will learn how to create a SELECT query to retrieve data from a given Excel worksheet using an OleDbCommand. We will populate and bind our data to our GridView using an OleDbDataAdapter and DataSet.
We will also look at using Server.MapPath to find a physical directory on the server. -
Section 4: Auto Formatting a Web Form GridView
In Section 4 of this tutorial by Nannette Thacker, we will learn how to add and Auto Format a GridView in our WebForm. We will also learn how to create and add a Cascading Style Sheet to our project.
We will learn more about the Design view, and look at applying a scheme via the AutoFormat functionality of the GridView. -
Section 3: FileUpload Control and Functionality
In Section 3 of this tutorial by Nannette Thacker, we are going to look at the "FileUpload" control. We will discuss how to set a Label text value and set Panel visibility from Codebehind. We will also learn how to use the Handles key word at the end of our procedure declarations to handle our Button Click events. We will also view a snippet of code that uses error handling through Try/Catch/Finally.
-
Section 2: WebForm: Table, Label, and Panel Controls
In Section 2 of this tutorial by Nannette Thacker, we learn how to work with our WebForm and define the properties of an ASP.NET Table control to layout our buttons. We will learn how to add controls for Buttons, Panels and Labels.
We will learn a little bit about the Design mode, by creating our Tables using the Design mode. -
Section 1: Creating Our Project, Database and Tables
In Section 1 of this tutorial by Nannette Thacker, we learn how to create a project and our SQL Server Database Tables using Visual Web Developer or Visual Studio 2005 or 2008. We will look at the design of our Excel Spreadsheet and create a new database and tables for our imported data.
We learn how to use the Solution Explorer (Solution Explorer in VWD and Server Explorer in Visual Studio), and use the Database Explorer. We learn how to add a table, set a primary key, and use the Identity Specifications property when creating a table column. -
Guids – Unique or not?
A GUID, (which may be pronounced goo-id or gwid), is a globally unique identifier.
The guid is a sequence of hexademical digits and looks something like this:
4F3104E0-3F89-12D3-7A0C-0405A82D3402
I’ve heard developers say that it is unique world-wide, yep, globally. But is it? I decided to do some research and find out based on other’s experience.
Wikipedia says “While each generated GUID is not guaranteed to be unique, the total number of unique keys (2128 or 3.4×1038) is so large that the probability of the same number being generated twice is very small.”
Hmm. Okay. But how about real-world experience? I am still skeptical. I find this sentence about GUIDs in an article by Scott Mitchell. A reader of Scott’s, Rusty Alderson, shares:
"In creating very large databases, GUIDs (as generated by MS's NEWID() function) WILL have collisions, or duplicates. In a previous project where I was building a large Customer ODS (Operational Data Store), I typically found about 4 collisions per million rows. Code has to be developed to handle this. This was in SQL Server 2000. Perhaps SQL Server 2005 has remedied this."
So there you have it. GUIDs are not globally unique. So now that we are in SQL Server 2008, what’s the verdict? Anyone working with millions of rows having collisions? -
Stored Procedures: CommandType.StoredProcedure, Insert/Update/Rollback/Select.
Here is a great example of working with stored procedures in your asp.net code.
-
Product Review: TredoSoft Multiple IEs
By Nannette Thacker
When developing, client specifications often include a requirement to support not only the Internet Explorer 7 (IE7) browser, but also Internet Explorer 6 (IE6). If you have IE7 installed on your PC and you try to find a version of IE6 to install, good luck with a successfull installation. I don't know how they do it, but the folks over at http://tredosoft.com/Multiple_IE have created a great program called Multiple IE's that installs not only IE6, but also optionally IE5, IE4, and IE3.
This is donation-ware and I do highly encourage you to donate if you use this program, for after all, the "laborer is worthy of his hire."
Installation is quite simple. Download. Click the EXE. Select which IE versions you want to install. You're done. The icons are on your desktop ready to use.
Note, the installer does not work with Windows Vista. But this blog post explains how to make IE6 work in Vista.
May your dreams be in ASP.net!
Nannette Thacker -
C# and VB Project: A Tutorial Using Data Sets, Table Adapters, WebForms, Controls, File Upload, Excel Import
In this tutorial by Nannette Thacker, we will create a VB or C# project from scratch. We will create DataSets, TableAdapters, a WebForm and Controls, a File Upload, and import and view an Excel Spreadsheet, and more! We'll also learn about intellisense and other features of Visual Studio or Visual Web Developer. This project may be used in both VS or VWD 2005 or 2008. Zip files with the complete source code in either C# or VB, Excel Spreadsheet, and .mdf SQL Server Database is available for download. You may easily modify this tutorial to use an existing database as well.
I have written this tutorial with step by step instructions and screen shots on how to do each point. If you are learning ASP.NET, please don't simply download the source code and plunk it into your project, the best way to learn is to walk through the tutorial from scratch and do each step yourself. -
Importing an Excel Spreadsheet Using Typed DataSets and TableAdapters: Importing the Excel Spreadsheet
By Nannette Thacker
In the final installment of this tutorial, we look at importing the uploaded Excel spreadsheet into the application database tables using the DAL.
The article series hosted on 4guysfromrolla.com continues with Importing an Excel Spreadsheet Using Typed DataSets and TableAdapters: Importing the Excel Spreadsheet.
Download the Application in ZIP Format -
Importing an Excel Spreadsheet Using Typed DataSets and TableAdapters: Creating a Data Access Layer (DAL)
By Nannette Thacker
In the fourth installment of this tutorial, we create the Data Access Layer (DAL) used to communicate with the application database during the import process.
The article series hosted on 4guysfromrolla.com continues with Importing an Excel Spreadsheet Using Typed DataSets and TableAdapters: Creating a Data Access Layer (DAL).
Download the Application in ZIP Format -
Instance versus Class (or Static) Members
If you're new to object oriented development, this web page I found on "Instance and Class Members" will come in handy for you.
-
Spam Catch without Captcha
By Nannette Thacker
Here is an example of how to set a spam trap without using Captcha. In your web form, typically a Register or Log In page, simply place a hidden textarea field. Then on your form action page, check the value and if it contains any content, you can redirect them to another page or do anything you like. Since a real human won't see or have access to this form field, only the bots will fill in the field.
ASP.net VB Example -
Importing an Excel Spreadsheet Using Typed DataSets and TableAdapters: Displaying the Uploaded Excel Spreadsheet
By Nannette Thacker
In the third installment of this tutorial, we discuss how to bind the contents of our uploaded Excel spreadsheet to our GridView. A Zip file with the complete source code, Excel Spreadsheet, and SQL Server Database is available for download.
The article series hosted on 4guysfromrolla.com continues with Importing an Excel Spreadsheet Using Typed DataSets and TableAdapters: Displaying the Uploaded Excel Spreadsheet.
Download the Application in ZIP Format -
Sweat to Mix08
-
Importing an Excel Spreadsheet Using Typed DataSets and TableAdapters: Building the Importer Web Page and Uploading the Excel Spreadsheet
By Nannette Thacker
In the second installment of this tutorial, we discuss how to build the ASP.NET page for importing the Excel spreadsheet. We will create the page's user interface and add file upload capabilities. A Zip file with the complete source code, Excel Spreadsheet, and SQL Server Database is available for download.
The article series hosted on 4guysfromrolla.com continues with Importing an Excel Spreadsheet Using Typed DataSets and TableAdapters: Building the Importer Web Page and Uploading the Excel Spreadsheet.
Download the Application in ZIP Format
May your dreams be in ASP.NET!
Nannette Thacker -
3-Tier Web Application Development
By Nannette Thacker
In web application development, three-tier architecture refers to separating the application process into three specific layers. What the user sees via a web browser is called the presentation tier and is content served from a web server. The middle tier performs the business logic processing that occurs, for example, when a user submits a form. The back end consists of the data tier which handles the database processing and access to the data. We'll take a simplistic look at each of these.
Presentation Tier
The Presentation Tier or User Interface is the portion the user sees when they open a web page in the browser. It is as simple as you reading this article all the way to searching a catalog and purchasing a product using a shopping cart. It is what is presented to the user on the client side within their web browser.
If you were to view the source code, you would only see code such as HTML, Javascript, and Cascading Style Sheets. On some sites, you may see Java Applets and Flash. Viewing source code on a web page, you would NOT see database queries or loops or calls to classes or any behind-the-scenes processing.
In ASP.net and utilizing Visual Studio or Visual Web Developer, developers can separate the user interface from the business logic and data access layer with various tools.
ASP.net allows using MasterPages to setup the site look and feel. As well, when creating a WebForm which utilizes the MasterPage, you may create it and allow the code to be placed in a separate file, known as codebehind, thus keeping your business logic in a separate layer from the look and feel.
You may also setup the site design using Themes, Skins, and Cascading Style Sheets.
Languages used in this layer are typically HTML, DHTML, CSS and javascript.
Business Logic or Application Tier
The Business Logic, Functional Process Logic, Business Rules (all pertaining to the same thing), are kept in a separate layer. In ASP.net, this is where you define your classes and source code. This can be in the App_Code folder for your classes and methods. Web languages typically used in ASP.net are VB and C#. You would not use HTML or Javascript in this layer. In this layer you typically define your classes, functions, sub procedures, properties, etc.
Data Access Tier
In ASP.net, the Data Access layer is where you define your typed datasets and tableadapters. It is where you define your queries or stored procedures. The business tier may then make use of this functionality. In your classes, rather than defining ad hoc queries, you may use a TableAdapter to access the Data Access Layer.
An Example
As an example of how this works, let's assume you are creating a web page that allows the user to enter information which you wish to then enter into a database. You first create a dataset and tableadapter that allows insert into the table, either by a query or stored procedure. This is your data access layer.
You then create a class, which retrieves the information from the form, checks for field validations and then uses the tableadapter to send the data to the database.
You create a web form, which can use a GridView control or other controls to allow the user to input the data into the web form. In the codebehind of the web form, you handle the submit button click event, and send the data from the form to your class, which sends the information to the database using the tableadapter.
Benefits
When utilized properly, using a multi-tier architecture improves performance and scalability. If a web page needs an update or redesign, all of this may be handled by altering the CSS and HTML, without affecting the business or data logic. Any of the three tiers may be replaced or upgraded individually without affecting the other tiers. For instance, if you change the database on the back end, it wouldn't affect the presentation or business logic tiers, other than changing the database connection.
This is a simple introduction to the three-tier web architecture, but I hope it has helped you understand the layers of a multi-tier architecture.
May your dreams be in ASP.net!
Nannette Thacker -
New Web Site Design
Check out our new website design and let me know what you think! (Maybe, if you're going to be nice that is. ;)
-
Custom MembershipProvider ConnectionStringName Usage
By Nannette Thacker
This is an issue that seems to confuse a lot of new developers. How do you use the "connectionStringName" defined within the membership provider area of the web.config file within a custom membership provider? Big mouthful, eh? Okay, let's break it down.
Within the web.config file, you may define your connection strings. For our example, below I am setting up a connection string to a SQL Server database within my project's App_Data folder, but it could be a connection string to a remote database on a database server as well. -
Importing an Excel Spreadsheet Using Typed DataSets and TableAdapters
By Nannette Thacker
In this tutorial, learn how to import data from an Excel Spreadsheet to a Database by creating a tiered application architecture using Visual Studio's Typed DataSets and TableAdapters. The application consists of an ASP.NET page that enables a user to upload an Excel spreadsheet, view the data in the spreadsheet, and import the data from the spreadsheet into the application's database. A Zip file with the complete source code, Excel Spreadsheet, and SQL Server Database is available for download.
The article series hosted on 4guysfromrolla.com begins with Importing an Excel Spreadsheet Using Typed DataSets and TableAdapters: Building the Database.
Download the Application in ZIP Format
May your dreams be in ASP.NET!
Nannette Thacker -
Creating a CSS Hyperlinked Image for Themes and Using ResolveClientUrl
By Nannette Thacker
In ASP.NET, you may define multiple themes to be used within your web applications. In this example, let's say you have a theme based around the color purple, and another theme based around the color blue. When using your purple theme, you have a special image, let's say a logo, that is designed with purple colors. But when using the blue theme, you want your logo to change to one that uses blue colors. This tutorial will show you how to setup your code within your master page so that you will pull this logo image from your cascading style sheet, rather than hard coding it within your master page or web form.
Normally, when defining a hyperlinked image, one would simply type an anchor tag and an image tag like so: -
OnClick and Handles Caution: Events Firing Twice
By Nannette Thacker
If you're new to ASP.NET, let me offer you a word of caution in regard to using theonclick
event within your controls and theHandles
key word within your procedure declarations. To demonstrate this, let's create a web form and add these two controls: -
Creating a Database Connection to a Remote SQL Server Database within Visual Web Developer
By Nannette Thacker
-
Retrieving Values from a DataReader
By Nannette Thacker
There are several ways to retrieve values from a DataReader.
The first method is by using the index and looping through the fields in order as retrieved within the Select statement. Starting with the 0 index, you may use the GetValue() Function.
The following code snippets are in VB. A C# snippet is provided at the bottom.reader = objCommand.ExecuteReader() While reader.Read() If Not reader.GetValue(0) Is DBNull.Value Then _ lastname = reader.GetValue(0) If Not reader.GetValue(1) Is DBNull.Value Then _ firstname = reader.GetValue(1) End While reader.Close()
However, this makes the code harder to read, and if a field is added or removed from the query, it could break your code. So let's look at how to retrieve the values by field names.
If your reader is using an OleDbDataReader, we use the reader.Item function.If Not reader.Item("lastname") Is DBNull.Value Then _ lastname = reader.Item("lastname") If Not reader.Item("firstname") Is DBNull.Value Then _ firstname = reader.Item("firstname")
If your reader is using a SqlDataReader, we use the reader.GetItem function.If Not reader.GetItem("lastname") Is DBNull.Value Then _ lastname = reader.GetItem("lastname") If Not reader.GetItem("firstname") Is DBNull.Value Then _ firstname = reader.GetItem("firstname")
Here is a C# example:if (reader["lastname"] != DBNull.Value) lastname = reader["lastname"].ToString();
A reader of my column, Zac, suggests that reader("lastname") instead of reader.Item("lastname") will also work.
He is correct. For the DataReader class implementation, Item is the default property and may be left out. You may access an indexer by using the () operator on the base class object or you may access an indexer by using the Item property.
Another reader of my column, Marneus, pointed out the GetOrdinal option as well. He said "there is a performance hit, each time you use the reader("lastname"), it has to check the meta datas to get the column number."
Readers may refer to this document on the GetOrdinal()
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getordinal.aspx
Please note this comment on efficiency:
"Because ordinal-based lookups are more efficient than named lookups, it is inefficient to call GetOrdinal within a loop. Save time by calling GetOrdinal once and assigning the results to an integer variable for use within the loop."
From the article, here is the usage:' Call GetOrdinal and assign value to variable. Dim customerID As Integer = reader.GetOrdinal("CustomerID") ' Use variable with GetString inside of loop. While reader.Read() Console.WriteLine("CustomerID={0}", reader.GetString(customerID)) End While
Another reader, AndrewSeven, pointed out the cost for hitting the reader twice for each field. He suggests:object val = reader["lastname"]; if (val != DBNull.Value) { lastname = val; }
And also comments "If your concern is readability, you should probably encapsulate the null test so you can write:lastname = GetValueFromReader(reader,"lastname");"
Travis responded with this suggestion: "Just do this, it handles nulls nicely unlike .ToString():"lastname = Convert.ToString(reader["lastname"]);
So I tested his theory by creating columns that would not allow null values, and imported columns with null values. In VB it is written like so:lastname = Convert.ToString(reader("lastname")) firstname = Convert.ToString(reader("firstname"))
That is much cleaner! Thanks everyone for your great input!
May your dreams be in ASP.net!
Nannette Thacker -
ASP.NET Links for Getting Started
By Nannette Thacker
-
Improving Page Download Time With Image Compression
by Nannette Thacker
-
Slick Rank Checker and Lake Quincy Ads
I noticed as I peruse the web that more and more of the articles websites I visit are covered with ASP.NET web ads. I wanted some for my site, Shining Star Software, so did a search on the asp.net blogs and found mention of the Lake Quincy ads. I thought I'd give them a try so applied.
I was asked my site's rank. Well, I don't track my site's rank with any tools, so I found this slick tool that will tell you your site's rank on Google and Alexa:
-
Microsoft OneNote 2007 for Organizing Source Code Snippets, Clients, Favorite Blogs and Articles
By Nannette Thacker
I discovered Microsoft Office OneNote 2007. I don't need all the fancy note sharing capabilities, but I'll show you what it does that is important to me as a developer.
-
Ajax Control Toolkit Installation in Visual Web Developer
by Nannette Thacker
-
Illustrator Image Edges and Anti-Aliasing
By Nannette Thacker
As a developer, many times I work with web graphic designers who provide me a layered template in Adobe Illustrator. It is my job to take each image and save it for the web, as well as design the style sheets and master pages.
Using Adobe Illustrator, I ran into a problem where when saving an image for the web, I noticed that Illustrator put a 1 pixel edge around the image. Not being a designer and Illustrator afficianado myself, I didn't know what was causing it or how to fix it. I tried nearly everything and finally found the solution. I want to share that for those who might have problems with this in the future.
Here is a view of what the image looks like with the edging I'm talking about. Notice the little white edges at the top and bottom.
Here is what I want it to look like, without the edging:
Here is the "secret." When on the "Save for the Web" page, select the "Image Size" tab, and deselect the "Anti-alias" checkbox and select "Apply." This will remove the edges from the image and save it the way it was designed.
May your dreams be in ASP.net!
Nannette -
OnLoggingIn Custom Method
And from design view, it looks something like this (depending on your background):
-
AutoEventWireup and Debugging Why Events Are Not Being Hit
What happens if you don't have "Handles Me.Load"? Nothing. Absolutely nothing. You'll run the page, but your Page_Load function will not run. You'll ponder why this code isn't being hit, and you'll even put in debug breakpoints and try to step through it, but it never hits your Page_Load. And until you remember this little tidbit of advice, you'll be pulling out your hair wondering why your code is being ignored.
-
HTML Tables to ASP.net Table Controls
If you're new to ASP.net, but familiar with ASP Classic or HTML, you might wonder about the ASP.net table control.
Dragging an HTML table from your toolbox...
... will generate these table commands: