Wednesday, May 14, 2008

Sys.WebForms.PageRequestManagerParserError in MS AJAX

Thanks to Al Pascual to solution.

On top of the webform add:

enableEventValidation="false"



To full article lick Here

Monday, April 28, 2008

Get column info in MS SQL

Existing some ways how to get column information, but Joe Webb offered very simple and effective query:

SELECT 
ORDINAL_POSITION
,COLUMN_NAME
,DATA_TYPE
,CHARACTER_MAXIMUM_LENGTH
,IS_NULLABLE
,COLUMN_DEFAULT
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME ='TABLE_NAME'
ORDER BY
ORDINAL_POSITION ASC;

Tuesday, April 08, 2008

VS 2005 Intellisense in web.config files stop work

Now one annoying gotcha:

There is one gotcha to be aware of, though, that can sometimes cause intellisense for the web.config file to stop working in the IDE. This happens when a default namespace is added to the root <configuration> element. For example, like so:

<configuration xmlns=
"http://schemas.microsoft.com/.NetConfiguration/v2.0">





This doesn’t cause any runtime problems – but it does stop intellisense completion happening for the built-in .NET XML elements in the web.config file.

The bad news is that the built-in web admin tool (launched via the WebSite->ASP.NET Configuration menu item in VS 2005 and Visual Web Developer) always adds this xmlns namespace when it launches – so if you use this tool to manage users/roles you’ll end up having it added to your web.config file for you.

How to fix this gotcha:

To get intellisense back when you are editing the web.config file in the IDE, just delete the xmlns reference and have the root configuration element look like so:

<configuration>



Everything will then work fine again.


via


Thursday, March 27, 2008

HttpWebRequest over SSL

public static bool
AcceptAllCertificatePolicy(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
}

The returned value determines whether the specified certificate is accepted for authentication.

Then set:

ServicePointManager.ServerCertificateValidationCallback
+= AcceptAllCertificatePolicy;

From here



Tuesday, March 18, 2008

Sunday, March 09, 2008

Singleton Factory in C#

    // this is the class for which
// I want to maintain a single instance
public class MyClass
{
private MyClass()
{
/* private constructor ensures that
callers cannot instantiate an
object using new() */
}
}

// Singleton factory implementation
public static class Singleton<T> where T : class
{
// static constructor,
//runtime ensures thread safety
static Singleton()
{
// create the single instance
// of the type T using reflection
Instance = (T)Activator.CreateInstance(
typeof(T),true);
}

// serve the single instance to callers
public static T Instance { private set; get; }
}

class Program
{
public static void Main()
{
// test
Console.WriteLine(
Object.ReferenceEquals(
Singleton<MyClass>.Instance,
Singleton<MyClass>.Instance));
}
}




via Cognitive Coding

Thursday, March 06, 2008

Monday, February 18, 2008

Enum Utilities

In this article I will discuss some classes I've written to simplify working with enumerations. The primary thrust of these classes is added functionality, but in some cases there are performance improvements as well.

Click here

Download source

The zip file contains:
EnumDefaultValueAttribute.cs
EnumTransmogrifier.cs
LibEnum.cs
build.bat
csc.rsp
EnumDemo1.cs
EnumDemo2.cs
EnumDump.cs
MonthEnum.cs
PolyglotAttribute.cs
WeekdayEnum.cs

Once you extract the files to a directory you should be able to execute build.bat to compile the demo programs. (They are console applications.)

To use the methods in your own projects, simply add the appropriate files.

Sunday, February 17, 2008

Directives in Asp.Net

Directives are used to pass optional settings to the ASP.NET pages and compilers.

Click here to read article.

Tuesday, February 12, 2008

Custom Controls: Extra Property Tab

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Elsehemy.Controls
{
[Designer(typeof(UserControlDesigner))]
[PropertyTab(typeof(ExtraSuperTab),
PropertyTabScope.Component)]
public partial class TestUserControl : UserControl
{
public TestUserControl()
{
InitializeComponent();
}
int _x;

public int XXX
{
get { return _x; }
set { _x = value; }
}
}


public class ExtraSuperTab :
System.Windows.Forms.Design.PropertyTab
{
public override PropertyDescriptorCollection
GetProperties(object component,
Attribute[] attributes)
{
PropertyDescriptor pd =
TypeDescriptor.CreateProperty(
component.GetType(),
"XXX",
typeof(int),
new CategoryAttribute("Super Properties"));

return (
new PropertyDescriptorCollection(
new PropertyDescriptor[]{pd}
));
}

public override string TabName
{
get { return "Super Tab"; }
}

public override System.Drawing.Bitmap Bitmap
{
get
{
return (System.Drawing.Bitmap)System.
Drawing.Image.FromFile(@"C:\icon.jpg");
}
}
}
}




 

And in the control don't forget the attribute

[PropertyTab(typeof(ExtraSuperTab),
PropertyTabScope.Component)]
public partial class TestUserControl : UserControl
 
Via Amr Elsehemy's Blog





Sunday, February 10, 2008

How to use delegates to remove duplicated code

Click Here

Static Extension Methods

DateTime d = DateTime.Yesterday();
//...
public static DateTime Yesterday<this DateTime>()
{
return DateTime.Today.AddDays(-1);
}
 


Via Mabstrerama

Tuesday, February 05, 2008

101 Design Patterns & Tips for Developers

Full guide for developer how to create your application in the using   a "design patterns", that include next parts:

  • Creational Patterns
  • Structural Patterns
  • Behavioral Patterns
  • Composing Methods of Refactoring
  • Moving Features Between Objects
  • Organizing Data
  • Simplifying Conditional Expressions
  • Making Method Calls Simpler
  • Dealing with Generalization
  • Big Refactorings

Click here to read.