Thursday, May 7, 2009

Normal people’s guide to visiting the US

Recently I was given the task to plan a US visit for 10 people.  My family and some family friends decided to come and visit me in the US for about a week or so as well as make trips to Niagara Falls, Washington D.C. and New York City – pretty much the most common destinations on the East Coast for all tourists. I had to plan their trip to the smallest detail and while doing it I had to answer a lot of simple questions like – where should we eat without breaking the bank and wasting time, what is a decent hotel that we can stay at, etc. Most guides already answer these questions but they do it assuming people want to go all out and try nothing but fancy dining. While this is true for some people, others like my family and friends don’t like shelling out $100/person every time. Don’t get me wrong – fancy food is okay every once in a while but simply not 3 times/day.

In this guide I will try to post some things that I thought were very helpful to them

Part 1: Food

This table will give you the basic idea about the most common places you could eat. It is being constantly updated so keep checking for new stuff. The number of “$” signs corresponds to the approximate amount you will pay per person per visit ie. 1 “$” sign = $10, 2 “$$” signs = $20 etc. This is a very rough figure and it will go up and down depending on what you actually order and how much you tip. While many of the full-service restaurants advertise cheap specials they are mostly during the day and without drinks and tip included. The cost here reflects both drinks and tip.
My suggestion is to print this table and when you get hungry and don’t know where to go – simply find the logo and get the details.

Name Logo Type Service Breakfast Alcohol Cost
Applebee’s

applebees

American Full   Yes $$
Arby’s

arbys

American Self No No $
Bob Evans

bob

American Full Yes No $$
Burger King

burger_king

American Self Yes No $
Cheesecake Factory, The

Cheesecake Factory Logo

American Full Yes Yes $$$
Chili’s

chilis

American Full Yes Yes $$
Denny’s

denny's

American Full Yes No $$
Domino’s

dominos

Pizza Delivery No No $
Eat’n Park

Eat'n Park

American Full Yes No $$
KFC

kfc

Chicken Self No No $
Long John Silvers

longjohnsilvers

Seafood Self No No $
McDonald’s

mcdonalds-logo

American Self Yes No $
Outback Steakhouse

OutbackLogo08

Australian Full   Yes $$
Perkins

Perkins-2000

Perkins Full Yes No $$
Pizza Hut

pizzahut

Pizza Full No No $$
Ponderosa

Ponderosa

American Full Yes No $$
Red Lobster

redlobsterogo

Seafood Full No Yes $$$
Ruby Tuesday

RubyTuesdayLogo

American Full   Yes $$
Subway

6

Deli Self Some No $
Taco Bell

tacobell-logo

Mexican Self No No $
TGI Friday’s TGI_fridays_logo American Full   Yes $$
Quiznos

quiznos logo

Deli Self No No $
Wendy’s

Wendy's

American Self No No $

Wednesday, November 12, 2008

How to render embedded text in an Image control with ASP.NET

The following quick tutorial will show you how to embed text in an image on an ASP.NET form in 2 simple steps.

The Render form

The first thing you have to do is add a the following form to the root of your website project

RenderImageWithText.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="RenderImage.aspx.vb" Inherits="RenderImage" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
 
    </form>
</body>
</html>

and the Code-behind

RenderImageWithText.aspx.vb

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
 
Partial Class RenderImage
    Inherits System.Web.UI.Page
 
    Public Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles Me.PreRender
        Dim imageFile As String = "image.jpg"
        Dim textToRender As String = "Sample Text"
 
        Dim imageToRender As New Bitmap(Server.MapPath(imageFile))
        Dim g As Graphics = Graphics.FromImage(imageToRender)
        g.SmoothingMode = SmoothingMode.AntiAlias
        g.DrawString(textToRender, New Font("Arial", 12), SystemBrushes.WindowText, 1, 1)
        Response.ContentType = "image/jpeg"
        imageToRender.Save(Response.OutputStream, imageToRender.RawFormat)
    End Sub
 
End Class

 

The background image

the second thing is to add any jpg file to the same location. Just make sure it is at least of some reasonable size and color for the test and has the same name as the value of the imageFile variable (in this case “image.jpg”)

 

Now if you preview the form you will see your text embedded in the image. Obviously you can use this from another form in bunch of different ways. In example you might want to display an email address but prevent it from ending up on some spammer’s list. In this case all you have to do is:

  1. In your RenderImageWithText form - replace the imageFile string value with a Request.QueryString(“Text”)
  2. In your working form add an ImageButton control that looks something like this
<asp:ImageButton ID="ImageButton1" Runat="server" ImageUrl="~/RenderImageWithText.aspx?Text=johndoe@mail.com" />

Clickable and Double-Clickable GridView in ASP.NET

The following code will make your GridView both single and double clickable. All you have to do is replace the Response.Write lines in the GridView1_RowCommand with anything that you want to do instead. Obviously you can change the styling as you please too.

The GridView

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="GridViewStyle">        
    <Columns>
        <asp:ButtonField CommandName="SingleClick" Visible="false" />
        <asp:ButtonField CommandName="DoubleClick" Visible="false" />
    </Columns>
    <RowStyle CssClass="GridViewRowStyle" />
    <SelectedRowStyle CssClass="GridViewSelectedRowStyle" />
    <HeaderStyle CssClass="GridViewHeaderStyle" />
    <AlternatingRowStyle CssClass="GridViewAlternatingRowStyle" />
</asp:GridView>

 

The Code-Behind

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
    Select Case e.CommandName
        Case "SingleClick"
            Response.Write("Single click detected")
        Case "DoubleClick"
            Response.Write("Double click detected")
    End Select
End Sub
 
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim SingleClickButton As LinkButton = e.Row.Cells(0).Controls(0)
        Dim DoubleClickButton As LinkButton = e.Row.Cells(1).Controls(0)            
        Dim singleClick As String = Page.ClientScript.GetPostBackClientHyperlink(SingleClickButton, "")
        singleClick = singleClick.Insert(11, "setTimeout(""")
        singleClick += """, 300)"
        e.Row.Attributes("onClick") = singleClick
        Dim doubleClick As String = Page.ClientScript.GetPostBackClientHyperlink(DoubleClickButton, "")
        e.Row.Attributes("onDblClick") = doubleClick
    End If
End Sub

 

The Optional CSS Style

<style type="text/css">
.GridViewStyle
{
    border:solid 1px #5D7B9D;
    color:#333333;        
    width:100%;
}
 
    .GridViewHeaderStyle
    {        
        background-color:#5D7B9D;
         font-weight:bold;
        text-align:left;
        color:White;                                
    }
    
        .GridViewHeaderStyle a
        {
            color:White;                                                
        }
    
        .GridViewHeaderStyle:hover
        {                             
        }
 
    .GridViewRowStyle
    {
        background-color: #F7F6F3;
        color: #333333;
    }
    
    .GridViewRowStyle:hover
    {
        background-color:Yellow; 
        cursor:pointer;            
    }
    
    .GridViewAlternatingRowStyle        
    {
        background-color:White;
        color: #284775;
        cursor:pointer; 
    }
    
    .GridViewAlternatingRowStyle:hover
    {
        background-color:Yellow;
        cursor:pointer; 
    }
  
.GridViewSelectedRowStyle
{
    background-color:Red;
    font-weight:bold;
}
  
</style>

The most important part to remember is the two ButtonFields. They should always stay in this order and the rest of your columns should be added after them.

Note: If you get an Event Validation or Invalid Callback or Postback Argument errors you must eiter

Apply this to your web.config to resolve your problem for the entire site

<system.web>
   <pages enableEventValidation="false"/>
</system.web>

or

Add this to the top of every page where you have this GridView

<%@ Page EnableEventValidation="false" %>

Tuesday, November 11, 2008

Bind Hyperlink.NavigateUrl to mailto: action without using code-behind

This is a very simple and elegant (but annoying to figure out) way to bind HyperLink.NavigateUrl to an email address with a mailto: action without using code-behind

 
 
<asp:HyperLink NavigateUrl=’&lt;%# Bind(”EmailAddress”, “mailto:{0}”) %&gt;‘ Text=’&lt;%# Bind(”Email”) %&gt;‘ runat=”serverID=”EmailHyperLink></asp:HyperLink>
 

 

Enjoy