Vertically align image to the middle

I was trying to align some text to an image vertically. I used the align attribute like this:

<img height=”28″ src=”/images/connect-phone.gif” width=”26″ align=”middle”> 234-234-2342

But this didn’t work in Firefox or Safari. So I sought out the CCS alternative. I came across this article explaining how to do it: http://www.webmasterworld.com/forum83/6588.htm . Here is the code supplied to answer the same question I had:

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Strict//EN”
“http://www.w3.org/TR/html4/strict.dtd”><html>
<head>
<title></title>
<style type=’text/css’>
body, html {
height:100%; /*fill the viewport*/
}
#container{
height:100%; /*fill the body*/
text-align: center; /*H-centering in early IE versions*/
}
#pinac {
width: 826px;
height: 155px;
position:relative; /*allows for top property to move the element*/
top:50%; /*moves it 50% of #container’s height down the page*/
margin-top:-77px; /*pulls it back up by half it’s height*/
margin-left: auto;margin-right: auto; /*H-centering in complaint browsers*/
background:#369;
color:#fff;
}
</style>
</head>
<body>
<div id=”container”>
<div id=”pinac”>This is your element.</div>
</div>
</body>
</html>

You’ve got to be kidding! Forget that. Instead I found I could just set align=”absmiddle” in the image. This attribute solved my problem, like this:

<img height=”28″ src=”/images/connect-phone.gif” width=”26″ align=”absmiddle”> 234-234-2342

I know CSS has it’s place but I’m still not much of a fan.

How to display ASP errors on Windows 2008 II7

By default ASP errors are not displayed on a Windows 2008, II7 server. The default error message displayed simply says:

Server Error
500 – Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.

This is for very good reason. Detailed error message can display sensitive information that you do not want public. But for development purposes we need to see the error message to properly resolve the error. Here are the steps to display the detailed error message.

In the IIS settings for the website:

1. Go to “ASP” (under IIS).

2. Set “Send Errors to Browser” to true.

If it still doesn’t display the detailed error follow these steps.

1. Go to “Configuration Editor” (under Management section).

2. Under system.webServer, select “httpErrors”.

3. Set errorMode to “Detailed”

Be sure to add proper error handling when taking the website live.

Setting WatermarkText in JavaScript

To set the Watermark Text of a TextBoxWatermarkExtender in the AJAX Control Toolkit, use the following code:

var behavior = $find('<%= TextBoxWatermarkExtender1.ClientID %>');
behavior.clearText();
behavior.set_Text('Hello World!');
behavior.initialize();

It took me a while to find that I needed to call the Initialize() function before the Watermark Text would get updated.


Update September 25, 2012

It appears that different versions of the AJAX Control Toolkit have different public methods.

var behavior = document.getElementById("<%= TextBox1.ClientID%>").AjaxControlToolkitTextBoxWrapper;
behavior.set_Watermark('');

http://stackoverflow.com/questions/2701875/ajaxtoolkit-textboxwatermarkextender-how-to-change-the-text-from-javascript

IE6 Float Bug

Lots of people like CSS and it certainly has it’s place. But when the most popular browser has a bug that prevents a simple div element from displaying properly we all get frustrated. All I wanted to do was have a box “float” to the right side of the page. It works great in IE7 and Firefox. IE6 displayed the box in the content area instead of to the right. See this page for more details. But the simple answer is add “display: inline” to the style. As I understand this, we are using a bug in IE6 to correct another bug in IE6. Okay, I grant you, this is confusing.

To fix the IE6 “float” bug to this:

<div class=”box”>
   <div class=”sidebar” style=”float: right; display: inline“>content
   </div>
   content
</div>

Source: http://www.positioniseverything.net/explorer/floatIndent.html

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.

 

ASP.Net CAPTCHA Control

Hello, 

I recently had a need to display a CAPTCHA on an ASP.Net contact form. After a short search on the internet, I found this article on the The Code Project: http://www.codeproject.com/KB/custom-controls/CaptchaControl.aspx

This Captcha control by Jeff Atwood was easy to plug in and works very well for my needs. I just wanted to let you know that it is out there.

– Zachary Lyons