ShowModalDialog Example – How to Save Popup Form Information and Close the Modal Popup Window
In this article I will go through a technique that you can use when working with a modal popup that lets you store form information from your popup to later use with your main Web form.
In earlier articles I have covered some of the general functions and benefits of using the ShowModalDialog function that I will expand on this article. If you have questions about some of the code I’ve used in this article, then please take a look at my earlier articles that might help explain some of the concepts:
Notes on Finding your WordPress.com Site Map and RSS Feed for Bing and Google
You can find this information scattered all over the Web, but I want to make a note of where to find your WordPress XML Site Map and RSS feed.
By the way, the Site Map and RSS feed URLs are just for sites hosted on WordPress.com and not self-hosted WordPress sites, but the WebMaster Tools information is applicable to everyone.
Knowing the location of your RSS and Site Map is especially useful information to have at hand when you are registering your site with Bing or Google. In both search engines it’s a good idea to submit both your RSS feed and your Site Map to their site maps section.
Basically I’m putting together this article to keep a list of useful links in place to refer to when managing one’s WordPress Web site. I have some other articles that cover general Web development topics that you might find interesting if you found this article useful. (more…)
ASP.NET – Handling Null Return Values from the Database using IsDBNull
If you are retrieving or adding values from and to your database then you will know the difficulties that can be caused by NULL values. The notorious InvalidCastException is one example of receiving a NULL value from your database into an ASP.NET object that doesn’t know what to do with database NULL values.
Here’s typical example of an InvalidCastException error caused by setting a String variable to a value that is returned as a NULL from your database query:
System.InvalidCastException: Conversion from type 'DBNull' to type 'String' is not valid. at Microsoft.VisualBasic.CompilerServices.Conversions.ToString(Object Value) at ASP.myPageName_aspx.Page_Load(Object sender, EventArgs e) in D:\Inetpub\wwwroot\MySite\myPageName.aspx:line 1xx
If you find this article useful, have a look at some of the other ASP.NET tips and tricks articles I’ve published. (more…)
JQuery – Example of Tabs Event Handling
If you are working with JQuery tabs and want to extend the functionality of your tabs beyond the basics, then it’s good to know how to handle the JQuery tabs click event.
In this article I will:
- Review how to add event handling to the JQuery tabs when a tab is clicked
- I will show how to load an iFrame contained in a tab when the tab is selected.
If you like this article, please have a look here for further useful articles about JQuery.
Setting the Z-Index and Page Position of a JQuery Modal Dialog
The JQuery modal dialog widget can be a useful tool on most Web pages. If you take a look at its structure in a tool such as FireBug you will see that it consists of a div that grays out the web page’s background, and another div that sits on top and that presents the modal dialog.
If you are adding absolute positioning and z-index markup to your Web page, then you will want to look a little deeper into the properties of your modal dialog widgets and how they interact with other elements on your Web page.
When an area of your page has a higher z-index than your modal dialog does, then the dialog will not be modal for that area, and may even be hidden by the area entirely. For example, if you have a text field on your form that is wrapped in an element with a z-index that is higher than that of your modal dialog, then your modal dialog will not gray out the text field. Even worse, the text field will remain editable which is certainly not desirable behavior.
If you find this article interesting, then take a look at my collection of articles on JQuery and the JQuery Modal Dialog widget.
(more…)
JavaScript – Generic Function to Toggle Div Element Visible or Invisible
If you are writing Web pages and find that you want to dynamically hide or show sections of your pages when the user interacts with the page, then the easiest way to do so is using JavaScript. In general it’s always best to avoid expensive round trips to the server by handling things client-side.
In this example we have two link elements that are click-able by the user. Each link element will show or hide a corresponding section of the Web page that has some example text. The sections to show/hide are HTML <div elements.
The nice part of this code is that you can write a single generic JavaScript function to take care of the click events. The link elements themselves pass the name of the <div to open or close. Once in the JavaScript function, the JavaScript determines whether to toggle the passed <div to show or not-show.
The same functionality of course can be written in several different ways, but most of these are more verbose and prone to breaking if something on the page changes.
Naturally the idea with this script is to expand on the code. If you are writing using ASP.NET at the server level, then you might use this code in a GridView control, or some sort of repeating list, or you could even use it to show custom page warning messages. The idea is that this functionality is simple to put in place and does not rely on any third party libraries.
(more…)
VB.NET – Reviewing String Collection Options
I’ll spend some time in this article reviewing some of the more common ways of handling String collections in VB.NET. Arrays in VB.NET do behave somewhat uniquely in several key aspects and working with them does take some getting used to for developers coming from a C# or Java background.
As with most things, there are several different ways of working with collections of strings in VB.NET:
- As a standard String array:
Dim saTest As String(9) - As a List collection:
Dim lstTest As New List(Of String) - As a StringCollection:
Dim scTest As New StringCollection()
Further, VB.NET does need special consideration when working with MutiDimensional and jagged MultiDimensional arrays. Your MultiDimensional options are:
- Directly manipulating a MutiDimensional array:
Dim saTest(1,0) As String - Working with jagged MultiDimensional arrays using embedded collections (i.e.: List embedded in List, or Dictionary embedded in List):
Dim lstTest As New List(Of Dictionary(Of String, String))
If you find this article to be useful, I have more VB.NET articles available on a range of topics that are worth a look.
(more…)
Using a JQuery DatePicker with an ASP.NET DataList and UpdatePanel
When you are developing a new Web form there are a number of useful technologies that you can use to enhance the functionality of the form. Today I will review combining an ASP.NET DataList control with a JQuery DatePicker widget, and also with an ASP.NET UpdatePanel. The complexity in this combination of controls comes into play with the interplay of the client side JavaScript along with the partial page reloading of DataList control in an UpdatePanel.
(more…)
ShowModalDialog – Example Code and Some Tips
Using the JavaScript showModalDialog function is a useful way for Web developers to create a modal popup. Unlike other popup functions, the showModalDialog function makes use of two separate HTML pages… one page as the parent page, and one page as the content of the modal dialog.
Developers will sometimes want the modal popup to be more than just a fancy version of the common alert() function. In this case, one has the option of creating a fully functional Web form in the Web page called from the showModalDialog function.
(more…)
ASP.NET – Example Connection Returning a Single Value
By definition, a scalar query will return the first column of the first row of a database query. In plain English this means it will return a single value. This can come in handy at times.
In the next series of articles I will cover the basic data connections including basic examples in C# and VB.NET.
One thing to note from the examples below is that I am using a try – catch – finally syntax to handle the clean-up of the command and connection objects. As an alternate syntax, you can make use of the Using object to handle the cleanup.
(more…)
ASP.NET Example – Populating a DataSet Using SQLDataAdapter Fill DataSet
In the example functions below I’m illustrating how to set up a basic query to a stored procedure in your database that takes a single string parameter. The examples involve using the SQLDataAdapter object to Fill a DataSet. The resulting DataTable can then be queried as desired. Specifically:
- The first example shows how to read the first row of the results after your Datatable has been populated. I provide the same example in VB.NET and C#.
- The second example shows how to loop through the results if you anticipate multiple returned rows. As before, I provide the same example in VB.NET and C#.
As part of this code, remember to include the correct .NET Namespaces. If you are writing your code inline (in either VB.NET or C#), use:
<%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %>
and if you are writing your code in codebehind, use:
VB Codebehind:
Imports System.Data Imports System.Data.SqlClient
C# Codebehind:
using System.Data; using System.Data.SqlClient;
Also, navigate here if you are interested in further articles I have written about ADO in .NET.
(more…)
Use a JQuery Modal Form Dialog to Add Rows to a GridView Control
Hooking up a JQuery Form Dialog Widget to an ASP.NET GridView Control
Let’s face it: the stock ASP.NET GridView control has some behaviors and limitations that aren’t exactly optimal. For starters, the lack of a nice way for users to add new rows to the grid is unfortunate. There are, of course, several different work-arounds for this all of which have their pros and cons.
I have been testing out using the JQuery Modal Form dialog widget as an input mechanism for new GridView rows. This has the benefit of not requiring the use of ASP.NET’s heavyweight ViewState and constant back and forth communication with the Web Server. Also, the modal nature of the widget on the Web form is a benefit.
The obvious drawback of using client side code is that the newly added rows are not stored in ViewState and you will need to handle them yourself. This really isn’t a big deal if you consider using Ajax calls to a Web Service rather than a complete form submission.
(more…)
SQL Server – Pass a List from your ASP.NET Code to a Stored Procedure using XML
Sometimes while developing a tool, a developer needs to pass a list of values with a variable size to their database. There are several ways of doing so, one of which involves passing the list in XML format.
The introduction of SQL Server 2005 offered the use of XML datatypes, which had not existed in previous versions of SQL Server. The good thing about the XML datatype is that it is not just good for storing information in XML format, but also has advantages such as being fully query-able similar to a database table.
As you look through this example, please feel free to check out other articles I have written for more SQL Tips
Here are the three main ways of passing lists of parameters to the different versions of SQL Server
A big benefit of the XML datatype is the ability to pass lists of items to stored procedures as XML format parameters. In SQL Server 2000 one would have to pass a list of parameters as a String that would then need to be parsed into its components in the Stored Procedure. This a tedious process that could easily introduce parsing errors. Subsequent versions of SQL Server have added extra ways in which to pass information lists to Stored Procedures:
- As a character-separated list contained in a String (VARCHAR) variable - SQL Server 2000 +
- As an XML variable – SQL Server 2005 +
- As a table variable – SQL Server 2008 +
As you can see from the list above, the methods of passing lists to stored procedures have increased in number over the last few iterations of SQL Server. The catch of course is that as a developer you will need to adapt your code to whichever instance of SQL Server your project is based on.
(more…)
Generate a PDF from an ASP.NET Web Page using the iTextSharp XMLWorker Namespace
If you need to quickly and easily generate PDF documents from ASP.NET, then the iTextSharp library is very convenient. To install and start using iTextSharp, you can download the zipped reference files from their Web site and then add them to your Visual Studio project the same way as you would do with any other third party library file.
The latest version of iTextSharp has deprecated their old HTMLWorker object in favor of the newer XMLWorkerHelper object. This is good news for any developer that likes to use CSS formatting since the older object did not support this. Likewise, the new object allows a number of important behaviors such as PDF page breaks that were impossible to do using the older object.
To make use of the XMLWorkerHelper object you will need to reference two DLL files in your Visual Studio project. These are:
- itextsharp.dll
- itextsharp.xmlworker.dll
Once you have referenced these two libraries you are ready to start coding.
(more…)
Correcting 404 Errors in IIS 6 When Running an ASP.NET ASPX Page
I was setting up a new Web Server that had been pre-installed with Windows 2003, IIS 6 and ASP.NET 2.0. The catch was that when I set up a new Web site on the server, I would get a 404 error page when the server was asked to serve up ASP.NET files (aka: files with the .aspx extension). Other files such as standard .html and .asp would render without problems.
I was a bit mystified until I realized that the setup of the pre-installed version of ASP.NET 2.0 on the server likely was done before IIS setup. Thus, although IIS showed ASP.NET 2.0 as an option, ASP.NET wasn’t properly registered with IIS.














