Tuesday, August 15, 2006

This is just a quick tip, but if you ever have problems converting your Coldfusion form values to a SQL Server database NULL before using an Insert or Update statement, the following info might help.

When you request form values from the submitting page make sure to use CFPARAM and give each form value submitted a default value, or just set to "" if the value doesn't matter.

<CFPARAM name="form.yourValue" default="">

Then when you execute your SQL command use CFQUERYPARAM to pass the value to SQL Server. Set the cfsqltype to your required data type. The trick to inserting the database null is to use the "null" attribute of CFQUERYPARAM. If you know that the form value will be null you can just pass the value directly to the "null" attribute, but if you don't know if a user has passed any data then check to see if you are passing an empty string and use the Coldfusion function YesNoFormat to create a Yes or No value for the "null" attribute.

It's not really as confusing as I made it sound - just use the the code snippet below and Coldfusion will create your database null values for you.

<CFQUERYPARAM value="#form.yourValue#" null="#YesNoFormat(NOT Len(Trim(form.yourValue)))#" cfsqltype="CF_SQL_INTEGER" />

Note:

For checkboxes you have to convert the value to 1 or 0 before using it in a SQL command. I just created a little function I call to do this:

function fixCheckbox(value) {
    var x
= "";
    
    
if (value EQ "on") {
        x
= 1;
    }
    
else {
        x
= 0;
    }        
    
return x;
}

8/15/2006 1:16:36 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, August 07, 2006

If your CSS doesn't seem to be rendering correctly even though you are 99.99% sure you're using the correct markup double check the doctype. If you don't explicitly set the doctype to transitional or strict the browser will default to CSS 1.0 specifications and many CSS 2.0 features aren't supported in the older version.

Make sure this is above the <html> tag:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Understanding DOCTYPE:

http://www.alistapart.com/articles/doctype/

 

CSS
8/7/2006 1:26:09 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, June 19, 2006

This tip is from DWTIPS - it's a good one. To reduce the time it takes to load a PDF you can disable some of the plug-ins that load everytime Acrobat is started up. Here's how you do it:

To disable unneeded plugins and make them optional instead, follow these instructions:

  1. Install the latest version of Adobe Acrobat - you can get it here
  2. Browse to the plugins folder: C:\Program Files\Adobe\Acrobat 7.0\Reader\plug_ins
  3. Create a new folder named Optional
  4. Move all files from the plug_ins folder to Optional, except EWH32.api, print*.api, and Search*.api
6/19/2006 12:38:04 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [1]  |  Trackback
 Wednesday, May 31, 2006

Microsoft recently launched a new IIS website. The site is mainly dedicated to IIS 7. It has some pretty cool utilities and lets you try out IIS7 through your browser. It might be worth checking out when you have a chance.

http://www.iis.net/

ASP.NET | IIS
5/31/2006 7:27:29 AM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Wednesday, May 24, 2006

Andy Hume posted an intersting article on bitesizestandards.com . It talks about positioning <divs> located on the source document in any order through css. Normally <divs> order themselves on the page according to the order they are placed on the page.

Here is a link to the article:

http://bitesizestandards.com/bites/understanding-any-order-columns

CSS
5/24/2006 9:34:20 AM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Friday, April 21, 2006

Typical Problem: ASP.NET <asp:login> works fine when tested locally, but doesn't work when deployed.

If you are setting up an ASP.NET application for deployment it's best to explicitly define the applicationName property on your membership provider - otherwise when you go to deploy the application you might run into problems.

The applicationName property in the web.config has to match the application path or application name of the web application - the paths are generally going to be different between your test and production environments.

So, the best way to make sure web.config stays correct for test and production is to set the application name through IIS.

Note:

Another thing to look out for when using the LoginView is that the control does not use the membership provider - it uses FormsAuthentication (for login status) and the RoleProvider for specific roles. You need to put the ApplicationName in your role provider as well:


<roleManager enabled="true" defaultProvider="SqlRole">
  <providers>
    <add name="SqlRole"
    connectionStringName="YOUR_CONNECTION"
    applicationName="appName" />
  </providers>
</roleManager>

 

 

4/21/2006 2:24:00 PM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [4]  |  Trackback
 Monday, April 10, 2006

ASP.NET Debugging with Trace.Warn

If you are trying to use Trace.Warn in your .NET application and you are getting an error that Trace is not declared than it probably means that you need to use the full object path declaration.

HttpContext.Current.Trace.Warn("Your String")

 

4/10/2006 7:45:17 AM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Friday, April 07, 2006

Adding a Confirmation to a Command Button

I'm coming from a Classic ASP background, so I'm used to just using JavaScript to control the client side functionality of command buttons, so when it came time to take control of the Cancel button created by an ASP.NET DetailsView I was stumped. There's probably a better way to do it, but this worked for me.

The command buttons are created in the last row of the DetailsView during the ItemCreated event, so first check if the footer row has been created:

If Not (DetailsView1.FooterRow Is Nothing) Then

The command bar that contains your action buttons it the last element in the Rows collection. Once you have the command bar you can loop through all of its controls and find the one your looking for. I was looking for the Cancel button:

Dim commandRowIndex As Integer = DetailsView1.Rows.Count - 1
Dim commandRow As DetailsViewRow = DetailsView1.Rows(commandRowIndex)
Dim cell As DataControlFieldCell = CType(commandRow.Controls(0), DataControlFieldCell)
' Loop through controls to find Cancel button
For Each ctl As Control In cell.Controls
  If TypeOf ctl Is Button Then
  Dim btn As Button = CType(ctl, Button)
    If btn.CommandName = "Cancel" Then
      btn.ToolTip = "Click here to cancel"
      btn.CommandName = "Cancel"
      btn.OnClientClick = "if(!confirm('Do you really want to discard the changes?')){return false;}"
    End If
  End If
Next

I wanted to add a confirmation to the Cancel the action, but you could use this example to add functionality to any of the command buttons. The confirmation button is created by adding a client side script to the OnClientClick property:

btn.OnClientClick = "if(!confirm('Do you really want to discard the changes?')){return false;}"

Putting it together:

Protected Sub DetailsView1_ItemCreated(ByVal sender As Object, ByVal e As EventArgs) Handles DetailsView1.ItemCreated

' Check that footerRow has been created
If Not (DetailsView1.FooterRow Is Nothing) Then
' Find Command Bar
Dim commandRowIndex As Integer = DetailsView1.Rows.Count - 1
Dim commandRow As DetailsViewRow = DetailsView1.Rows(commandRowIndex)
Dim cell As DataControlFieldCell = CType(commandRow.Controls(0), DataControlFieldCell)
' Loop through controls to find Cancel button
For Each ctl As Control In cell.Controls
  If TypeOf ctl Is Button Then
  Dim btn As Button = CType(ctl, Button)
    If btn.CommandName = "Cancel" Then
     btn.ToolTip = "Click here to cancel"
     btn.CommandName = "Cancel"
     btn.OnClientClick = "if(!confirm('Do you really want to discard the changes?')){return false;}"
    End If
  End If
Next
End If
End Sub

Redirecting User on Command Click

The next thing I wanted to do was redirect the user to a different page if they confirmed the cancel action. First I created a sub called "Get_Command" and then I called it from the OnItemCommand of the DetailsView.

Here's an example:

<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False"
DataSourceID="ObjectDataSource1"
OnItemCommand = "Get_Command">

And this code goes in your Code Behind file:

Sub Get_Command(ByVal Src As Object, ByVal Args As DetailsViewCommandEventArgs)

If Args.CommandName = "Cancel" Then

Response.Redirect("~/yourPage.aspx:")

End If

End Sub

Conclusion

I hope somebody finds this post and it saves them a little time. If somebody knows a better way to do this - I'd love to see it.

4/7/2006 8:28:56 AM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [6]  |  Trackback

It's really easy to set the display size of a multi-line textbox in .NET once you know the correct properties to set.  The multi-line textbox is equivalent to an <HTML> textarea.

To control the number of lines that display to the user you can set the "rows" property and to control the display width you can set the "width" property. You can also set the CssStyle of the textbox to control the width.

Here's an example:

<asp:TextBox ID="txtYourTextBox" runat="server" rows="6" TextMode="MultiLine" Width="450px" Text="Your text"></asp:TextBox>

4/7/2006 7:45:10 AM (Eastern Standard Time, UTC-05:00)  #    Disclaimer  |  Comments [0]  |  Trackback