Monday, October 26, 2009

ASP.NET - CSS ID selector vs. CSS class for custom server controls

To have a common use control, we do create custom ASP.NET server controls.
As a simple example let's have a side bar control. To do that, Add a Web User Control, it has .ascx extention and call it sideBarList.

<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="sideBarList.ascx.cs"
Inherits="AspAdvWrk01.sideBarList" %>

<asp:Panel ID="srchEnginePnl" runat="server">
<h4>Search Engines:</h4>
<a href="http://www.bing.com/">bing</a><br />
<a href="http://www.google.ca/">Google</a><br />
<a href="http://m.www.yahoo.com/">Yahoo</a><br />
<a href="http://www.msn.com/">MSN</a><br />
<a href="http://www.altavista.com/">Altavista</a>
</asp:Panel>

Then let's add the following CSS codes in a style sheet:

#srchEnginePnl
{
border-style:dotted;
border-width:1px;
padding: 5px;
font-size:small;
}

I tried the same ID name of asp Panel control in this style sheet as a CSS ID selector, To apply style to the asp Panel control with ID name of srchEnginePnl. Even though that we have CSS ID selector but it doesn't apply any style because the real ID name in HTML page is something else which you can find it by checking the html source of the page in your browser (in the test page it was #ctl00_ContentPlaceHolder1_sideBarList1_srchEnginePnl).

The solution, a CSS class selector and utilizing CssClass attribute as following:

.srchEnginePnl
{
border-style:dotted;
border-width:1px;
padding: 5px;
font-size:small;
}

a.srchEnginePnl
{
padding: 10px;
}

...
<asp:Panel ID="srchEnginePnl" CssClass="srchEnginePnl" runat="server">
...

otherwise you have to use the real ID of your panel control in html source and use that ID name to define the ID CSS selector in your style sheet:

#ctl00_ContentPlaceHolder1_sideBarList1_srchEnginePnl
{
border-style:dotted;
border-width:1px;
padding: 5px;
font-size:small;
}

...
<asp:Panel ID="srchEnginePnl" runat="server">
...

Share/Bookmark

Sunday, October 25, 2009

Visual Studio 2010 and .NET Framework 4 Training Course


Links to new Interview videos and How Do I clips and new posts about Visual Studio 2010 Beta2 in Channel 9.
http://channel9.msdn.com/learn/courses/VS2010/

"The Visual Studio 2010 and .NET Framework 4 Training Course includes videos and hands-on-labs designed to help you learn how to utilize the Visual Studio 2010 features and a variety of framework technologies including:
  • C# 4.0
  • Visual Basic 10
  • F#
  • Parallel Computing Platform
  • WCF
  • WF
  • WPF
  • ASP.NET AJAX 4.0
  • ASP.NET MVC Dynamic Data."

Share/Bookmark

Tuesday, October 20, 2009

Visual Studio 2010 and .NET Framework 4 Beta 2


The Visual Studio 2010 and .NET Framework Beta 2 is available to MSDN subscribers on Monday, October 19th. Visual Studio 2010 Beta 2 and Dot Net framework 4 Beta 2 will be made available to the general public on 21st October. Users will be able to get their hands on the final version of Visual Studio 2010 on 22nd March 2010.
http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx

Visual Studio 2010 and .NET Framework 4 Beta 2 Walkthroughs
http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx

Testers to get Visual Studio 2010 Beta 2 this week; final by March 2010
http://blogs.zdnet.com/microsoft/?p=4270&tag=content;col1

Other links:
Microsoft names Visual Studio 2010 dates
http://www.theregister.co.uk/2009/10/19/visual_studio_2010_second_beta_packaging/

http://msdn.microsoft.com/en-us/vstudio/default.aspx

http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx
Share/Bookmark

Sunday, October 11, 2009

Visual Studio - An error occurred loading this property page

If you found out that the "Design, Split, Source" buttons are not available anymore, your first reaction would be to take a look at Tools->Options->HTML Designer, at this point probably you encounter with this error message:
"An error occurred loading this property page"

I encountered with the error and it was resolved by running "devenv /setup" in Visual Studio 2008 Command Prompt and restarting Visual Studio. The "Design, Split, Source" buttons came back to the right place after running that command.
Share/Bookmark

Saturday, October 10, 2009

ASP.NET - Image handler to fetch and show Images from varbinary(MAX)

Imagine you want to get images from [Production].[ProductProductPhoto] table in AdventureWorks SQL sample database. The following code can be in a generic handler (.ashx) file.

public class ImgHandler : IHttpHandler
{
private string sqlCnStr =
   ConfigurationManager.ConnectionStrings["CnStrAdvWrk"].ConnectionString;

public void ProcessRequest(HttpContext context)
{
   string productId = context.Request.QueryString["PrdId"];
   if (string.IsNullOrEmpty(productId))
      productId = "1";

   using (SqlConnection sqlCn = new SqlConnection(sqlCnStr))
   {
   StringBuilder cmd = new StringBuilder();
   cmd.Append("SELECT PrdPhoto.[ThumbNailPhoto] as PrdPhoto ");
   cmd.Append(" FROM [Production].[Product] as Prd ");
   cmd.Append(" JOIN [Production].[ProductProductPhoto] as PPrdPhoto ");
   cmd.Append(" ON Prd.ProductID = PrdPrdPhoto.ProductID ");
   cmd.Append(" JOIN [Production].[ProductPhoto] as PPhoto ");
   cmd.Append(" ON PPrdPhoto.ProductPhotoID = PPhoto.ProductPhotoID ");
   cmd.Append(" WHERE Prd.[ProductID] = " + productId);

   sqlCn.Open();
   SqlCommand sqlCmd = new SqlCommand(cmd.ToString(), sqlCn);
   SqlDataReader sqlDtaRdr = sqlCmd.ExecuteReader();
   sqlDtaRdr.Read();
   context.Response.BinaryWrite( (byte[]) sqlDtaRdr[0] );
   sqlCn.Close();
   context.Response.End();
   }
}

   public bool IsReusable
   {
   get { return false; }
   }
}


Now you just need to call the handler.

If you have an image control and you know the ProductId:

<asp:Image ID="Image1" runat="server"
ImageUrl="~/ImgHandler.ashx?PrdId=1" />


or if you have a GridView and you want to have a column with product images, then you can use TemplateField with and Image control inside the ItemTemplate:

<asp:TemplateField HeaderText="Image">
   <ItemTemplate>
      <asp:Image ID="Image1" runat="server"
      ImageUrl='<%# "ImgHandler.ashx?PrdId=" + Eval("PrdId") %>' />'
   </ItemTemplate>
</asp:TemplateField>

Share/Bookmark

Wednesday, October 7, 2009

Error 2738 - during installation of Adventure Works sample databases on Vista

Well, I downloaded Adventure Works sample databases from the here
but I encountered with error 2738 during installation.

I found the solution by a post in Mitch Denny blog:
http://notgartner.wordpress.com/2008/07/12/the-error-code-is-2738/

In brief the solution was to register VBSCRIPT.DLL on Vista which is not registered by default.
- Run "Command Prompt" as administrator
- Switch to "C:\WINDOWS\SysWOW64"
- Execute "REGSVR32.EXE VBSCRIPT.DLL"


Share/Bookmark

Tuesday, October 6, 2009

ASP.NET - Do you need a GridView with scroll bars?

If you are looking for a GridView control that scrolls inside a web page, well, it's simple.
- Add a panel control
- Place the GridView control inside the Panel
- Set the panel size
- Set the Panel.Scrollbars property to Vertical, Auto, or Both!
Share/Bookmark