Friday, May 30, 2008

New Beta Sites

Check this out...
www.evernote.com
This web site has OCR Build in which can search on handwriting inside your image 
     image image
http://www.tripit.com/ - If you like traveling 

Thursday, May 29, 2008

Dynamic Data on ASP.NET 3.5 Extensions CTP

I recently try Dynamic Data on ASP.NET 3.5 Extensions CTP.

The most thing that impress me is an idea of Dynamic Control /Field.

<asp:DynamicControl runat="server" DataField="EmailAddress"/>



So you can just simple define Dynamic Field in your Grid View and it will rendered into particular template (Include Edit Template) based on data type of your value.




You can define your template to have validation control or even can you 3rd party control such as telerik.



Here is How you can tell dynamic control to render based on particular template or even BLOB/Image Type as well.




//this is a partial class to override the code which has been generated by DBML
[MetadataType(typeof(MyClassMetadata))]
public partial class MyClass
{
//TODO: You may put Validation when your data change or whatever...
}

//Here is your metadata which you will define rendering using UIHint
public class MyClassMetadata
{
//Date Type
[DisplayFormat(DataFormatString="{0:dd MMM yyyy}")]
public object StartDate {get; set;}

//Integer Type
[Range(0,10, ErrorMessage="Please enter valid quantity between 1-10")]
public object Quantity {get; set;}

//Text type using 3rd Party WSYWIG control
[UIHint("TextEditorTelerik")]
public object Description {get; set;}

//Blob - image type
[UIHint("DbImage")]
[ImageFormat(200,200)]
public object Picture {get; set;}
}



UIHint is where you define your template.


You can create whatever for your template name and just put "_Edit" for edit mode.


Just see the sample in under FieldTemplates of your Dynamic Data Project



Singleton Confusion

I heard some developers asked about this question "If you can create a static class, Why do we need to create a Singleton Class ?"

I think the answer is straight forward.

Singleton Pattern is a pattern that will make sure there is only 1 instance. on the other hand It will make sure that developers will not be able to another instance.

Static Class will share your instance through your application. But this static class will not make sure that it will only be 1 instance of your class. Other developer which don't know where you put your static instance will able to create the new instance... and It will be any duplication and waste of resources.

Here is very simple Singleton pattern.

public class MySingleton
{
//Your exclusive instance
private static MySingleton _Instance;

//this will make sure no one can create an instance of this class.
private SampleSingleton(){}

//this static constructor will be the only who can create an instance of this class
static MySingleton()
{
//TODO: you may preinit / validation code before create an instance
_Instance = new MySingleton();
}

public static MySingleton Instance
{
get{ return _Instance;}
}
}

Wednesday, May 14, 2008

Increase AJAX Performance by using Composite Script

As you can see in Web Developer tool, there is a lot of request happening on the background.

The first thing you need to do before combining Ajax scripts, You need to know what scripts are being used by your pages.

Add this on your pages to detect what scripts are being used.

<microsoft:ScriptReferenceProfiler runat="server"/>



After that Copy all the Script References which is written by Script Reference Profiler.



And Paste it into Script Manager Composite Scripts.




<asp:ScriptManager runat="server">
<CompositeScript>
<!-- Paste Here -->
<asp:ScriptReference name="~/Scripts/MyCustomScripts.js"/>
<asp:ScriptReference name="MicrosoftAjax.js"/>
<asp:ScriptReference name="MicrosoftAjaxWebForms.js"/>
....
....
<!-- -->
</CompositeScript>
</asp:ScriptManager>



And as a results you can decrease the number of request and traffic for this scripts.

PS: The ScriptReferenceProfiler control is not part of the Beta installation, and you must install it separately. Download this http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=aspnet&ReleaseId=13356.

Wednesday, May 7, 2008

Bug Fix For Unknown Runtime Error for Gridview inside Update panel

 

image

If we use CSS Friendly,
This happen if I put GridView Under Update Panel without table.

But finally I found that in my master page there is this strange tag.
<a name="body" />

After remove this, Everything works fine.
Here is the reference.
http://damianpedwards.spaces.live.com/blog/cns!A079DE667E1958B3!562.entry

The most explanation that I found so far is this
=====From Lewis =====
http://cyrilgupta.com/wp/?p=110
I found that this error is caused by having a a html ‘form’ element somewhere inside the postback html.
After taking out the form tags (and any asp.net controls generating them) from the updatePanel’s contentTemplate, the error went away.
=====================

However , I still don't understand If I put your GridView outside update panel and keep EnableSortingAndPagingCallbacks="True"


When I click on Paging and Sorting, It throw error Microsoft JScript runtime error: 'panelElement' is null or not an object.
image

I think this is cause by CSS Friendly, because If I take the CSS Friendly out for GridView, It works fine
Any comment ?

Tuesday, May 6, 2008

LINQ to SQL Debugging

There are several ways to debug your Linq to sql

  • Sql Server Profiler
    But How about if you share your Sql Server with others such as staging DB ?
    It will be nightmare.
  • DataContext Command
    Console.WriteLine(ctx.GetCommand(prods).CommandText);
    But How about if you don't want to write any debug code ?
  • LINQ to SQL Debug Visualizer
    I think this is the best way to debug your LINQ to SQL.
    You can use .NET Debugging Mode

    And Click small magnifying glass in the expression above, It will launch the LINQ to SQL debug visualizer to inspect the raw SQL that the ORM will execute based on that LINQ query:

Click "Execute" button, you can even test out the SQL query and see the raw returned results that will be returned from the database:

Installing SQL debug Visualizer :

  1. Download Linq to Sql Debug Visualizer http://www.scottgu.com/blogposts/linqquery/SqlServerQueryVisualizer.zip - (From Scott Gu Blog)
  2. Copy from \SqlServerQueryVisualizer\bin\Debug\SqlServerQueryVisualizer.dll
    image
  3. Copy to C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers
    image

You may start debug your LINQ...