Clear previously entered text box values

Sometimes we do not want the browser to display previously entered values in an input box. These are the values that dispaly somewhat like a drop down list. To clear previously entered text box values we can add the following attibute to the input box parameters:

    autocomplete=”off”

This will not show data that had been entered before.

 

GridView.RowDataBound Event No Data

I was trying to use the GridView.RowDataBound event to change the background color of the row in a GridView. But the data was missing. Here is what I trying:

void gvReport_RowDataBound(Object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
      if (e.Row.Cells[1].Text.IndexOf(“Total:”) > 0)
         e.Row.BackColor = System.Drawing.Color.FromArgb(247, 249, 223);
   }
}

But my e.Row.Cells[1].Text had no data in it. I am binding the grid in code so maybe that is why the grid would not show any data. Here is what I did to get it to work:

protected void gvReport_RowDataBound(object sender, GridViewRowEventArgs e)
{
   if (e.Row.RowType == DataControlRowType.DataRow)
   {
      DataRowView rowdata = (DataRowView)e.Row.DataItem;
      if (rowdata[1].ToString().IndexOf(“Total:”) > 0)
         e.Row.BackColor = System.Drawing.
Color.FromArgb(247, 249, 223);
   }
}

Hope this helps someone else.

 

Setting Page Meta Information at Runtime

I have a MasterPage and some child pages. The content for the child pages comes from a database. I have a form in the Admin section of my site for editing pages. You can set the Page Title, the Meta Description, Keywords, and page Content.

Accessing the title is easy, because the title of the content pages (in the @Page directive) applies to the MasterPage. Getting to the Meta information is a little trickier.

Thanks to Chris Garrett for his tip at http://aspalliance.com/411_Setting_the_ASPNET_Page_Title_and_Meta_Tags.

First, in the content pages, I have to add

<%@ MasterType VirtualPath=”~/MasterPage.master” %>

to the child pages, right under the @Page directive. With this, I can type “Master.” in the codebehind and access all the public properties of the MasterPage.

Second, on the MasterPage, I have to add two Public Properties. One for the Meta Description, and one for the Meta Keywords.

Public MetaDescription As String = “”
Public MetaKeywords As String = “”

Third, in the HTML code for the page, I make the two Meta tags server controls. I always set the Head tag to runat=”server”.

<head runat=”server” id=”Head1″>
<title
/>
<meta id=”Description” runat=”server” content=”description” name=”description”
/>
<meta id=”Keywords” runat=”server” content=”keys” name=”keywords” />

Fourth, on the Page_Load of the MasterPage, I can set the Title and Keywords at runtime.

Description.Attributes(“content”) = “Demo Description”
Keywords.Attributes(“content”) = “Keyword 1, Keyword 2”

I am now pulling the Meta information directly from the database at runtime, and setting Page.Title, Master.Description, and Master.Keywords from the Load event of the Child page.

In the Load event of the MasterPage, I can add some simple logic to give all pages a meta description.

If MetaDescription.Length = 0 Then
    Description.Attributes(“content”) = “My Generic Description. This description appears on all pages where the MetaDescription in the database is empty.”
Else
   
Description.Attributes(“content”) = MetaDescription
End If

If MetaKeywords.Length = 0 Then
   
Keywords.Attributes(“content”) = “Generic, Default, Consistent, Normal”
Else
   
Description.Attributes(“content”) = MetaKeywords
End If

This is how I use MasterPages, and it works pretty well!

Zachary Lyons

Outlook Stationary

To create stationary for Outlook follow these steps:

  1. Create stationary as a local .htm page. Put the images in the same folder.
  2. Copy the .htm page and images into one of these folders:
    Vista – C:\Users\<logon user>\AppData\Roaming\Microsoft\Stationery
    XP – C:\Documents and Settings\<logon user>\Application Data\Microsoft\Stationery

Then your stationary will be listed as a theme under the Signatures and Stationary settings in Outlook.

This page has a list of various Outlook file locations: http://www.slipstick.com/config/backup2007.asp

 

JavaScript Code To Toggle Check Boxes

Here is some JavaScript code to toggle check boxes (same action as radio buttons).

In the page load event register the JavaScript: 

   chkTwoYear.Attributes.Add(“onclick”, “javascript: CheckTwoProgram(” + chkTwoYear.ClientID + “);”); 
   chkFourYear.Attributes.Add(“onclick”, “javascript: CheckFourProgram(” + chkFourYear.ClientID + “);”);

In the HTML of the page add the JavaScript:

<SCRIPT Language=”JavaScript”><!–
function CheckTwoProgram(id) { 
   if(id.checked) 
      document.forms[0].chkFourYear.checked=false; 
   }
function CheckFourProgram(id) { 
   if(id.checked) 
      document.forms[0].chkTwoYear.checked=false; 
   }
//–>
</SCRIPT>