How to set column width in a CheckBoxList in an ASP.NET page

Maybe this is common problem since CheckBoxList control doesn't have set of parameters for obtaining column width and row height. But we always can use CSS for styling this control getting in mind he is rendered as html table or floated div tag.


<asp:checkboxlist runat="server" id="chkBoxList1" cssclass="chkBoxList" repeatcolumns="4" repeatlayout="Table">
</asp:checkboxlist>


Here we explicitly define the layout to be rendered as table (which is by default) and also need to define the css class "chkBoxList" in current page or web site theme.


<style>
.chkBoxList tr
{
height:24px;
}

.chkBoxList td
{
width:120px; /* or percent value: 25% */
}
</style>

Of course any other css styles can be attached here.

Only ASP.NET :)

SQL Stored Procedures - getting return value

Starting directly with example:

CREATE PROCEDURE ProcessValue
(
@value int,
@returnValue int OUTPUT
)
AS
BEGIN
/* do calculation and processing and assign the result value to output parameter */
SET @returnValue = value + 5*value

END

The following calling of the procedure shows how to get output parameter.
declare @result int
EXEC ProcessValue 15, @result OUTPUT


Of course this example is pretty simple - only for showing how to use. For such usage the SQL scalar-valued functions are better way.

Way for localizing MessageBox in Windows Forms

Very good article in code project, where you can see how the buttons of MessageBox can use custom text labels. The natural language of .NET platform will be overridden and only your labels will be shown.

http://www.codeproject.com/KB/miscctrl/Localizing_MessageBox.aspx

Actually if you use MessageBoxOptions in the parameters of MessageBox.Show(..) only the original labels are shown. But I don't think this is big problem.

How to map an extension for server side scripting - html to php

Sometimes we need including some functionality or server includes into static web files - html. But changing the extension can lose current search engine index and rank. That is why leaving the fiels with the same name is the better way. Easy html files can be mapped to be parsed as php file.

IIS 7.0:
1. Open IIS Management Console
2. Open Web-site node
3. Open Handler Mapping
4. Add the extension as request path (*.html)
5. Set the handler application/library: something like C:\Program Files\PHP\php5isapi.dll
6. Name it and click OK

Apache:
Just add the following row in the .htaccess file:
AddType application/x-httpd-php .html

SQL Server 2005 - Out Of Memory exceptions connected to its RAM usage

After the allocated RAM for SQL Server exceeds the System memory unexpected behavior of the server is present.

Here is a quick guide for configuring Sql server.

http://www.mattec.com/service/appnotes/820-0019.pdf

And remember: Never allocate less then 1 GB of RAM to SQL Server :)

VB.NET: General Exception Handling in Windows Forms

VB.NET

My.Application.UnhandledException Event is the way for handling all unhandled exceptions in an windows forms application. The application raises this event when it encounters unhandled exception.
For using the event editing ApplicationEvents.vb file is needed. By default ApplicationEvents.vb is hidden. For openning (unhiding) it use Project Properties -> Application tab -> View Appication Events.
Then the handler can be added/edited as in the example below:

Private Sub MyApplication_UnhandledException( _
ByVal sender As Object, _
ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs _
) Handles Me.UnhandledException

Try
//write log, which is nessted in Application Data folder
My.Application.Log.WriteException( _
e.Exception, _
TraceEventType.Critical, _
"Unhandled Exception!")

//check up if the Event folder exists.
//if not - create new one
If Not EventLog.SourceExists("My software") Then
EventLog.CreateEventSource("My software", "My Software")
End If

//write event log, can be seen by Event Viewer
EventLog.WriteEntry("My software", _
e.Exception.ToString(), _
EventLogEntryType.Error)
Catch ex As Exception

End Try

// code for notifying the user with user friendly message
...................

//set the default application action (closing) not to be performed.
e.ExitApplication = False
End Sub
And from now on all unhandled exception in the application will be stored as exception information and stack trace in the application log file or in the Windows Event log and the user will receive friendly message.


C#

Of course most of my posts give examples with VB and C# when they are different. Now I will give up this pleasure to R. Newman with his great post "Top-level Exception Handling in Windows Forms Applications"

How to check the type of an object or control using VB.NET or C#

The VB.NET check up is:

If (TypeOf sender Is TextBox)Then
Dim txt As TextBox= DirectCast(sender, TextBox)
End If



And the C# code:

if (sender Is TextBox){
TextBox txt=(TextBox)sender;
}

Error reporting in PHP run on IIS

The PHP error reporting is controlled either by the php.ini file as a global setting or programatically, or using .htaccess.

The error reporting in php.ini is defined in "Error handling and logging" section.
  • error_reporting = E_ALL & ~E_NOTICE - shows all errors except E_NOTICE errors. E_NOTICE are possible errors which can occur even during normal program workflow - something like Microsoft's warnings.
  • display_errors = On
  • display_startup_errors = On
Programmatically the same settings are applied for current site like this:
ini_set('display_errors','1');
ini_set('display_startup_errors','1');
error_reporting(E_ALL & ~E_NOTICE);

In .htaccess the flags must be changed in the following way:
php_flag display_errors 1
php_flag display_startup_errors 1


Php error_reproting help -> http://php.net/error_reporting

URL Encoding - reserved and unsafe characters

RFC 1738: Uniform Resource Locators (URL) specification is described in the following page. Also simple convertor is included.

http://www.blooberry.com/indexdot/html/topics/urlencoding.htm


Server.URLEncode(url)
applies these rules to the url. During getting an url parameter from the query string the value will be automatically decoded.

Javascript trace log

Simple and useful tool can be found here:

http://v2.easy-designs.net/code/jsTrace/


Using it you can get rid of the alert messages while debug applications.

How to excute string with javascript

Simply use eval().

eval('peformAction()') will execute

Adding a relationship between DataTables

A DataTable can be related to another DataTable in the same DataSet using DataRelation object. Using DataRelation the navigation between DataTable (foreign key connection) becomes very easy.

An example for using Child Relation is located here:
http://msdn.microsoft.com/en-us/library/system.data.datatable.childrelations.aspx

Here is an example for using Parent Relation:

We have two DataTables: DataTableOrder (OrderId is foreign key to DataTableOrderDetails) and DataTableOrderDetails (Id is primary key)

//create dataset
DataSet dataSet = new DataSet();

//add existing tables to the DataSet
dataSet.Tables.Add(DataTableOrder );
dataSet.Tables.Add(DataTableOrderDetails);

// create relation between both tables
dataSet.Relations.Add(
dataSet.Tables[1].Columns["Id"],
dataSet.Tables[0].Columns["OrderId"]);

foreach (DataRow row in DataTableOrder .Rows)
{
//get parent rows using relation - all order details for current order
//use GetParentRows for relations 1 to many
DataRow dr=row.GetParentRow(dtm.ParentRelations[0]);
//check if there is a parent row
if(dr!=null){
Response.Write(row["OrderName"].ToString() +"->"+ dr["OrderDetails"].ToString() +"
")
}
}

Good working free CAPTCHA control for asp.net


CAPTCHA stands for "Completely Automated Public Turing test to tell Computers and Humans Apart" and means software peace which makes user input challenges which are easy for solving by humans and difficult for machines. The purpose is to avoid spam or hackers attacks which can harm your data or make unpredictable responses.

This post will show you one very good CAPTCHA control, which is tested by me and works fine, even with ajax. It is easy for use and will save you time to develop such control.

Thanks for Mondor software.
http://www.mondor.org/captcha.aspx

Why don't you have .NET 3.5 as a selectable framework in IIS

The reason is that the .NET Framework 3.5 delivers not whole new runtime machine, but only library extension of .NET 2.0. In other words there are no new CLR or new language compilers. But there are new available libraries and new versions of C# (3.0) and VB (9)

.NET Framework 2.0 includes the CLR, Winforms, Asp.NET and web services.

.NET Framework 3.0 includes in addition libries for WCF (Windows Communication Foundation), WPF (Windows Presentation Foundation) and Windows Workflow (WF).

.NET Framework 3.0 includes in addition libraries for AJAX, LINQ and REST

Finally you will see there is no problem with your IIS. You've just received some new additional and really good features for easier programming.

Gmail consider the mail as SPAM. How to avoid that?

Obviously Gmail uses Sender-ID and DKIM to verify every email. That is why you need to modify DNS records for your domain using txt record. Here is a tutorial how to do that openspf.org.
You can build your txt records using the wizard and add them. You need something like:
record for domain.com in txt: v=spf1 a mx ~all
record for the mail server mail.domain.com in txt: v=spf1 a -all