Centering a DIV inside a DIV – Both Horizontal and Vertical

I was recently facing this issue of centering a DIV both horizontally and vertically inside another DIV. Here’s the solution I came up with. I have tested the solution in IE7, Mozilla 3 and Chrome 2

<!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>
<
meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<
title>Foo foo</title>
<
style type="text/css">
div
{
border:thin gray solid;
}

#parentDiv {
position:relative;
height:500px;
width:100%;
}
#childDiv {
position:absolute;
top:50%;
height:250px;
width: 50%;
margin-top:-125px;
margin-left:250px;

}
</style>
</
head>

<
body>
<
div id="parentDiv">
<
div id="childDiv">Your Text Goes Here</div>
</
div>
</
body>

</
html>
OUTPUT

image

Adding a ToolTip to an ASP.NET Hyperlink Control in a GridView

I recently came across a cool solution proposed by Jose to add a tooltip to an ASP.NET Hyperlink control kept inside a GridView. The solution is to create a template field and add a Hyperlink control to it as shown below:

<asp:TemplateField HeaderText="SomeLink">
<
ItemTemplate>
<
asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# Eval("SomeLink") %>' Text='<%# Eval("SomeLink") %>'
ToolTip='<%# Eval("SomeText") %>'>
</
asp:HyperLink>
</
ItemTemplate>
</
asp:TemplateField>

RSS to PDF - Email your RSS FEED to your subscribers In a PDF Format using Tabloid

One of my www.devcurry.com visitors Dewel, mailed me asking if the RSS feed of this site could be delivered to his email in a PDF format. I found the request interesting!

On investigating, I came across a tool called Tabloid (http://www.tabbloid.com). Tabloid is a free service from Hewlett Packard which turns your feeds into PDF. You also have the option to schedule the pdf to be delivered to the email addresses you have chosen.

image

Enter your RSS feed in the textbox given and click on ‘Generate Sample Issue’ now (at the bottom) to view how the PDF will appear.

The PDF generated is pretty good. It was not able to format the code snippet too well, but did well for images as well as Text. The layout generated was similar to a magazine format. Here’s a sample of what got generated.

image

So go ahead and try it out!

Win Windows 7 Ultimate and a Cool windows 7 T-Shirt

Windows 7 will be available in stores on October 22, 2009.

Stephen (Sr. Community Manager, Microsoft) in his blog announced a chance for you to win a copy of Windows 7 Ultimate OS or a cool Windows 7 T-shirt when Windows 7 hits the stores. Fill out a survey comprising of just 7 multiple choice questions over here http://is.gd/Z2Te

The survey closes early next week. It took me less than a minute to answer the questions. Go on and give it a shot. Who knows you may be amongst the lucky ones!

Cause a PostBack on KeyPress from the asp.net dropdownlist

I recently bumped into a solution given by Vince Xu where he suggested a technique of causing a postback from a dropdownlist on any keypress. If you desire, you can easily filter the key code and cause postback on specific keypress. This technique can be useful when you plan to Implementing KeyBoard Shortcuts in ASP.NET applications 

Here’s how to cause a postback from DropDownList on keypress

C#

protected void Page_Load(object sender, EventArgs e)
{
if (Request.Params["__EVENTTARGET"] != null)
{
string evnt = Request.Params["__EVENTTARGET"].ToString();
string args = Request.Params["__EVENTARGUMENT"].ToString();
if (evnt == "DropDownList1" && args == "onkeypress")
{
// write some code to execute on postback
}
}

DropDownList1.Attributes.Add("onkeypress",
Page.GetPostBackEventReference(DropDownList1,"onkeypress"));
}



VB.NET




Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As EventArgs)
If Request.Params("__EVENTTARGET") IsNot Nothing Then
Dim
evnt As String = _
Request.Params("__EVENTTARGET").ToString()
Dim args As String = _
Request.Params("__EVENTARGUMENT").ToString()
If evnt = "DropDownList1" _
AndAlso args = "onkeypress" Then
' write some code to execute on postback
End If
End If

DropDownList1.Attributes.Add("onkeypress",_
Page.GetPostBackEventReference(DropDownList1, "onkeypress"))
End Sub

Quickly GENERATE a String collection with a repeated value using linq

If someone were to tell you to generate a string collection with just one value, you would immediately create a loop and populate the string. With LINQ, this requirement becomes very simple using the ‘Repeat’ Generation operator as shown below:

C#

void Main()
{
IEnumerable<string> someString =
Enumerable.Repeat("I am repeated", 10);

foreach (string s in someString)
Console.WriteLine (s);
}



VB.NET



Private Sub Main()
Dim someString As IEnumerable(Of String) = _
Enumerable.Repeat("I am repeated", 10)

For Each s As String In someString
Console.WriteLine(s)
Next s
End Sub


OUTPUT



image

Generating a Bulleted List dynamically using jQuery

Recently I had to take a list of items from a service and display it in a Bulleted List dynamically created. The requirement was to use plain HTML and jQuery. Here’s how to do so:

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Display Progress</title>
<
script src="Scripts/jquery-1.3.2.js"
type="text/javascript"></script>

<
script type="text/javascript">
$(document).ready(function() {
var geoList = [
{ Country: "India", State: "Delhi" },
{ Country: "US", State: "Alabama" },
{ Country: "US", State: "Georgia" },
{ Country: "US", State: "Texas" },
{ Country: "US", State: "NewYork" }
];
$('#LoadPage').append("<ul id='cList'></ul>");
for (i = 0; i < geoList.length; i++) {
$("#cList").append("<li>" +
geoList[i].Country + "-" +
geoList[i].State + "</li>");
}
});
</script>
</
head>
<
body>
<
form id="form1">
<
div>
<
div id="LoadPage">
</
div>
</
div>
</
form>
</
body>
</
html>



OUTPUT



image

ASP.NET and SQL Server Books You Must Read

 

I recently published a list of ASP.NET, AJAX, MVC, Architecture, Silverlight, LINQ, JavaScript, jQuery, CSS and SQL Server Books You Must Read. Here are the links for them

SQL Server 2008 Books You Must Have In Your Collection

15 Books You Must Have If You Are Doing ASP.NET Web Development

Go and check them out!