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

Sunday, September 20, 2009

CSS - height loose when all elements are float in a <div> block

When all the elements in a <div> block are float, Firefox can't keep the height of block, in this example the border appears just on top side:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
   <meta http-equiv="Content-Type"
   content="text/html; charset=iso-8859-1">

   <title>height loose</title>

</head>

<body>
   <div style="margin:auto;width:350px;border:5px solid #CCC;">
      <img style="float:left;margin-top:0.5em" src="Design.jpg" />
      <span style="float:right;margin-top:1em; margin-right:0.5em">
      <b>Development</b>
      </span>
   </div>
</body>
</html>


To solve the problem, it's necessary to explicitly set the height of block and it's better to use em for height size unit cuz of covering different font size of contents:


   <style type="text/css">
      #hdr {
         height: 4em;
      }
   </style>

   <div id="hdr" style="margin:auto;width:350px;border:5px solid #CCC;">
   ...
   </div>


IE doesn't show such a behavior, it's yet another place that coder should consider cross browser development techniques.
Share/Bookmark

Saturday, September 19, 2009

ASP.NET - URL Mapping in Web.config

The URL mapping feature uses configuration information stored in web.config to remap incoming requests to a different URL. The remapping occurs prior to any other processing for the inbound request. Although the sample below demonstrates remapping a page request, any arbitrary file type can have its request remapped to a different URL.

Imagine some body kept the URL of your web site in their bookmarks and you want to change the pages and structure of your site so that it affects the URLs, then you need to redirect the old ones to new correct destination, it works if you consider URL mapping.

The URL mapping feature uses to redirect incoming requests to a different URL. Prior to any other processing for the incoming request the remapping happens.

URL Mapping stores in web.config file, inside <system.web> tag, it's possible to add elements in <urlMappings>. In <add> tag there is url attribute which points to exact value of incoming url and mappedUrl attribute keeps value of rewritten url which is the exact redirected destination.


<configuration>
   <system.web>
      <urlMappings>
         <add url="~/LCDs.aspx" mappedUrl="~/prds.aspx?prdCat=lcd" />
         <add url="~/DVDs.aspx" mappedUrl="~/prds.aspx?prdCat=dvd" />
         <add url="~/MP3s.aspx" mappedUrl="~/prds.aspx?prdCat=mp3" />
      </urlMappings>
   </system.web>
</configuration>


With URL mapping, the redirection works the same as the Server.Transfer() method, and browser will still show the original incoming request URL, not the mapped URL.

The Request.RawUrl property returns the original request URL.
The Request.Path property reflects the result of mapped URL.
Request.QueryString["yourQueryStringElement"] also return the result from the mapped URL.

If we have a site map provider in our web page, it first try to use the original request URL when looking for the node in the site map which is provided by Request.RawUrl, if it doesn't find the matched record, it uses the Request.Path property.

Incomming Request --->
   Mapping available in Web.config?
      --- YES ---> Use mappedUrl path --->
                                                      [Render requested path]
      --- NO --------------------------------->
Share/Bookmark

Thursday, September 17, 2009

Free Web Hosting - Web Hosting Company Reviews

Free Web Hosting list by ABOUT.com

Web Hosting Company Reviews
The data is based on reviews by people who have used the web hosting services from the hosting companies.
Share/Bookmark

10 Best and Worst Web Hosting Providers!

Something interesting from ABOUT.com, at least it worth to take a look at the following lists, I don't want to say that I'm agree or disagree with the result which ABOUT.com collected, it's just interesting.

10 Best Web Hosting Providers
As Rated by About.com Readers

10 Worst Web Hosting Providers
As Rated by About.com Readers

Last updated 21 April 2009
Share/Bookmark

Friday, September 11, 2009

ASP.NET - EventLog Class - Custom logs


It's a good idea to log errors and unexpected conditions in event log. But if you want to record user actions or other data which repeats a lot and consume considerable amount of space, the Event Log is not a good choice and may be it's better to log it in database tables or XML files, because Event log uses disk space and takes processor time and it will affect overall performance of machine and our application.

EventLog class in System.Diagnostics namespace allows us to utilize related functions in .NET, on the other hand, it's a good practice to make a custom errors log and record messages related to our application there. Then Event Viewer will collect messages in an individual place which allows us to keep track of them easily. the following sample code implements custom event logging idea.

try
{
// ...
// you code here
// ...
}
catch (Exception ex)
{
string logName = "myWebAppEventLog";
if (!EventLog.SourceExists(logName))
{
EventSourceCreationData escd =
new EventSourceCreationData("myWebAppSrc", logName);
escd.MachineName = System.Environment.MachineName;
EventLog.CreateEventSource(escd);
}
EventLog evntLog = new EventLog(logName);
evntLog.Source = "myWebApp";
evntLog.WriteEntry(ex.Message, EventLogEntryType.Error);
}


To find more you can take a look at following URLs and or search online.
- EventLog Class
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog%28VS.71%29.aspx

- How to manage event logs using Visual C# .NET or Visual C# 2005
http://support.microsoft.com/kb/815314

- Security Ramifications of Event Logs
http://msdn.microsoft.com/en-us/library/4xz6w79h%28VS.71%29.aspx
Share/Bookmark

Thursday, September 3, 2009

TypeDescriptor.GetConverter - unified way of converting types of values to other types

...
string[] brdrStyleAry = Enum.GetNames(typeof(BorderStyle));
rbtnBrdr.DataSource = brdrStyleAry;
rbtnBrdr.DataBind();
...
TypeConverter objCnvrtr =
TypeDescriptor.GetConverter(typeof(BorderStyle));
pnlCard.BorderStyle =
(BorderStyle) objCnvrtr.ConvertFromString(rbtnBrdr.SelectedItem.Text);

Share/Bookmark

Tuesday, August 25, 2009

Partitioning utility - EASEUS Partition Master Home Edition (FREE)


"EASEUS Partition Master Home Edition is a FREE disk partitioning utility for extending system partition, better disk space management, settling low disk space problem under Windows 2000/XP/Vista"
http://www.partition-tool.com/personal.htm

Overview:

* Extend system partition to maximize computer performance.
* Main features for better managing hard disk and maximizing computer performance.
* Copy wizard to backup all data or copy entire hard disk to another without Windows reinstallation.
* Usability features allow you to operate directly on the disk map with the drag-and-drop and preview the changes.


Main Features:

* Resize/Move partitions without data loss
* Extend system partition easily and safely
* Create, Delete and Format partitions with simple steps
* Support up to 2TB partition or hard drive
* Disk Copy, Partition Copy, Dynamic Disk Copy to protect or transfer da
Share/Bookmark

Monday, August 17, 2009

SQL - How to rename a DATABASE physically in MS SQL Server 2008

As you know sp_renamedb stored procedure does not rename the database data files. I prefer to have the database data files contain a matching database name. If I have a database named [myDataBase], then the data files would typically be myDataBase.mdf and myDataBase_Log.ldf, simple and neat. In this way, just with take a look at the files, I can remember which SQL database they are talking about. Otherwise it's confusing.

SQL 2008 allows us to rename a database using T-SQL and the sp_renamedb stored procedure has been deprecated. ALTER DATABASE can do the job for us.

You can code as following to do the job:

1- Change your database name:
ALTER DATABASE oldDataBase
MODIFY NAME = newDataBase
GO

2- Rename master data file (.mdf):
ALTER DATABASE AutoMac
MODIFY FILE(NAME = 'oldDataBase', NEWNAME = 'newDataBase' )
GO

3- Rename log file:
ALTER DATABASE AutoMac
MODIFY FILE(NAME = 'oldDataBase_Log', NEWNAME = 'newDataBase_Log' )
GO

4- Assign new full path file name to renamed master data file:
ALTER DATABASE AutoMac
MODIFY FILE (NAME='newDataBase', FILENAME='C:\mySQLfiles\newDataBase.mdf')
GO

5- Assign new full path file name to renamed log file:
ALTER DATABASE AutoMac
MODIFY FILE (NAME='newDataBase_Log', FILENAME='C:\mySQLfiles\newDataBase_Log.ldf')
GO

6- Now you need to take the database offline (Tasks->Take Offline) and bring it back online (Tasks->Bring Online), then you don't need to detach and attach your database again.
Share/Bookmark

Saturday, August 15, 2009

SQL Server 2008 - Warning: Saving Changes Not Permitted

If [Prevent saving changes that require table re-creation] option in [Table Options] of [Designers] in SSMS [SQL Server Management Studio] is ON, when you want to save a table that requires the table be dropped and recreated behind the scenes, you will see the following warning. It can happen if you want to modify a column data type, data type size, or to add a new column in a specific location, or ...



Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created.

The solution is turn off the option in Tools -> Options then go to [Designers] page and uncheck [Prevent saving changes that require table re-creation] option.




Share/Bookmark