Using OleDb – DataBase is not updated and No Errors

When editing/updating a database with OleDb – here are two things to make sure of:

  1. Make sure the defining parameter (ie: Where uid=@uid) in the Where clause is actually getting populated
  2. When using parameterized queries, OLEDB parameters are positional. Make sure the parameters are defined in the same order as they appear in the SQL update string.

Could Not Load type (namespace.filename) error

If you are using VS.Net, in the Page Directive’s Inherits property, it normally puts it in this format:
Inherits = “Namespace.Webform1″
When you get this error, try removing the Namespace and the period between the two.

Also, add the Src property, duplicating the page in the CodeBehind property. The CodeBehind property is for VS.Net, so if you are continuing to edit in VS.Net, you should not remove it.

[Your Field Name] is neither a DataColumn nor a DataRelation for table [Your Table Name].

If you’re getting this message and you know beyond a shadow of a doubt that this field/column DOES, indeed, exist in your table, then, check your SQL query to make sure you included the field name in the query.
(Most likely, it was forgotten)

The two possible reasons are that, either it doesn’t exist in the table, or it doesn’t exist in the SQL query.

Max Length/Multiline TextBox Controls – using Postback

As you may have already found out, the MaxLength property does not work with the ASP.Net Multiline TextBox control. To get around this, though it’s not immediate (due to the fact that it’s a server-side process), like with the Single Line mode of the textbox control, in your button’s click event, you can handle it something like the following:
The Scenario :
1 MultiLine textbox (id=txtMultiline)
You don’t want more than 100 characters entered

Dim sInfo as String
sInfo=txtMultiLine.Text

if sInfo.Length>100 then
	lblerror.text="You entered " & sInfo.length & " characters. Please limit to 100 characters."
	exit sub
End If

By using the ‘exit sub’ command, and putting this before the rest of the form submission code, the fact that too many characters are entered is

Adding a Print Button with Javascript

If you’d like to use an ASP.Net button for printing, all you need to do is :
Add this line to the Page_Load event

btnPrint.Attributes("onClick") ="javascript:window.print();"

Add a button to the page called ‘btnPrint’

Technically, that’s it, but, let’s say you want to do something a little fancier, using DotNet. Then, add a subroutine (let’s call it ‘DoPrint’):

Sub doPrint(Source as Object, E as EventArgs) lblResults.visible="True" lblResults.text="Page has successfully been sent to the printer!" End Sub

Then, add a direction to this sub, in the button’s tag:

onServerclick="doPrint"

That’s all there is to it!

ItemStyle/HeaderStyle Properties not working with DataGrid

Remember that a DataGrid generates an HTML Table, with TableRows and Cells. If you have ItemStyle/HeaderStyle/SelectedItem/FooterStyle tags with display properties (like forecolor/bold/font properties) and some of them are not displaying like you think they should, be sure to check your page for a StyleSheet.

If you have a TD tag section in your page’s stylesheet – -whatever properties you set there will normally override whatever you add into your DataGrid’s Item styles.

PlaceHolder vs. Panel

Functionality-wise, both server controls are generally the same. They both act as containers, separating other server controls, etc., into logical sections.

However, the Panel has a bit more overhead. A panel has most of the display/decoration/style capabilities of the other server controls (border style/width/color, BackColor, Font, CssClass, etc).

The PlaceHolder control doesn’t have most of those capabilities. It’s major function is to act as a container for other tags/server controls.

So, if you just want a container, without all the Display properties, use a PlaceHolder. If you want to use it to separate controls visually, then, the Panel is the control for you.

Numeric-Only Textboxes

If you haven’t heard of the built in ASP.Net Validator controls, it’s time to learn. There are several, but, for this case, you would use a Regular Expression Validator. The Regular Expression for making sure only numeric data is inserted into the textbox is:

^([0-9]*|\d*\d{1}?\d*)$

You’d use it in a Regular Expression Validator, in conjunction with an ASP.Net Textbox, like this:

<asp:TextBox id="txtNumber" Runat="server" /> <asp:RegularExpressionValidator ID="vldNumber" ControlToValidate="txtNumber" Display="Dynamic" ErrorMessage="Not a number" ValidationExpression="(^([0-9]*|\d*\d{1}?\d*)$)" Runat="server"> </asp:RegularExpressionValidator>