Thursday, May 22, 2008

Who want to use Photosynth next ?

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...

Tuesday, April 29, 2008

Custom CSS for Calendar Extender (AJAX Control Toolkit)

You may specify your custom CSS for your calendar in your application.

Just put copy this style and change your custom style

For general Calendar

.ajax__calendar_container {padding:4px;position:absolute;cursor:default;width:170px;font-size:11px;text-align:center;font-family:tahoma,verdana,helvetica;}
.ajax__calendar_body {height:139px;width:170px;position:relative;overflow:hidden;margin:auto;}
.ajax__calendar_days, .ajax__calendar_months, .ajax__calendar_years {top:0px;left:0px;height:139px;width:170px;position:absolute;text-align:center;margin:auto;}
.ajax__calendar_container TABLE {font-size:11px;}
.ajax__calendar_header {height:20px;width:100%;}
.ajax__calendar_prev {cursor:pointer;width:15px;height:15px;float:left;background-repeat:no-repeat;background-position:50% 50%;background-image:url(<%=WebResource("AjaxControlToolkit.Calendar.arrow-left.gif")%>);}
.ajax__calendar_next {cursor:pointer;width:15px;height:15px;float:right;background-repeat:no-repeat;background-position:50% 50%;background-image:url(<%=WebResource("AjaxControlToolkit.Calendar.arrow-right.gif")%>);}
.ajax__calendar_title {cursor:pointer;font-weight:bold;}
.ajax__calendar_footer {height:15px;}
.ajax__calendar_today {cursor:pointer;padding-top:3px;}
.ajax__calendar_dayname {height:17px;width:17px;text-align:right;padding:0 2px;}
.ajax__calendar_day {height:17px;width:18px;text-align:right;padding:0 2px;cursor:pointer;}
.ajax__calendar_month {height:44px;width:40px;text-align:center;cursor:pointer;overflow:hidden;}
.ajax__calendar_year {height:44px;width:40px;text-align:center;cursor:pointer;overflow:hidden;}

.ajax__calendar .ajax__calendar_container {border:1px solid #646464;background-color:#ffffff;color:#000000;}
.ajax__calendar .ajax__calendar_footer {border-top:1px solid #f5f5f5;}
.ajax__calendar .ajax__calendar_dayname {border-bottom:1px solid #f5f5f5;}
.ajax__calendar .ajax__calendar_day {border:1px solid #ffffff;}
.ajax__calendar .ajax__calendar_month {border:1px solid #ffffff;}
.ajax__calendar .ajax__calendar_year {border:1px solid #ffffff;}

.ajax__calendar .ajax__calendar_active .ajax__calendar_day {background-color:#edf9ff;border-color:#0066cc;color:#0066cc;}
.ajax__calendar .ajax__calendar_active .ajax__calendar_month {background-color:#edf9ff;border-color:#0066cc;color:#0066cc;}
.ajax__calendar .ajax__calendar_active .ajax__calendar_year {background-color:#edf9ff;border-color:#0066cc;color:#0066cc;}

.ajax__calendar .ajax__calendar_other .ajax__calendar_day {background-color:#ffffff;border-color:#ffffff;color:#646464;}
.ajax__calendar .ajax__calendar_other .ajax__calendar_year {background-color:#ffffff;border-color:#ffffff;color:#646464;}

.ajax__calendar .ajax__calendar_hover .ajax__calendar_day {background-color:#edf9ff;border-color:#daf2fc;color:#0066cc;}
.ajax__calendar .ajax__calendar_hover .ajax__calendar_month {background-color:#edf9ff;border-color:#daf2fc;color:#0066cc;}
.ajax__calendar .ajax__calendar_hover .ajax__calendar_year {background-color:#edf9ff;border-color:#daf2fc;color:#0066cc;}

.ajax__calendar .ajax__calendar_hover .ajax__calendar_title {color:#0066cc;}
.ajax__calendar .ajax__calendar_hover .ajax__calendar_today {color:#0066cc;}



If you specify your CSS Class in calendar Extender, you may use this.




        <ajaxToolkit:CalendarExtender ID="customCalendarExtender" runat="server" TargetControlID="Date2"
CssClass="MyCalendar" Format="MMMM d, yyyy" SelectedDate="April 28, 1906" PopupPosition="Left"/>







.MyCalendar .ajax__calendar_container {
border:1px solid #646464;
background-color: lemonchiffon;
color: red;
}
.MyCalendar .ajax__calendar_other .ajax__calendar_day,
.MyCalendar .ajax__calendar_other .ajax__calendar_year {
color: black;
}
.MyCalendar .ajax__calendar_hover .ajax__calendar_day,
.MyCalendar .ajax__calendar_hover .ajax__calendar_month,
.MyCalendar .ajax__calendar_hover .ajax__calendar_year {
color: black;
}
.MyCalendar .ajax__calendar_active .ajax__calendar_day,
.MyCalendar .ajax__calendar_active .ajax__calendar_month,
.MyCalendar .ajax__calendar_active .ajax__calendar_year {
color: black;
font-weight:bold;
}

Multiple IE

Running Multiple IE in your desktop is very useful for web tester.
Download Multiple IE installer (10.3MB)

setup pic1

setup pic2

Monday, April 28, 2008

MVP Pattern in ASP.Net

why we need to use MVP ?

• No Code Reuse - Each view (page/control) must create an instance of a specific presenter in order to invoke the presenter's methods. That's four or five lines of code per page/control; quite a bit of work if you have hundreds of pages and controls in your site. Code can and should be centralized.
• Presenter Creation - Presenters operate on a specific type of interface. Generally speaking, there's a one-to-one relationship between presenters and interfaces. This problem relates to the "no code reuse" point, and leads to inconsistent public-facing functionality exposed by various presenters. Object creation should be standardized.
• View Intelligence – Using the MVP pattern forces a view to know as much about its presenter (methods, properties etc…) as the presenter knows about its view. The use of interfaces prevents a circular reference, but there should still be further decoupling of the view. One area I may disagree with Bill is that views should also not know what data layer type (or DAO interface type) to pass to a presenter. I'm of the opinion that the view's shouldn't have a reference to any data layer (i.e. anything upstream of the presenters).
• State Management – This one is a biggie. Many of the people posting on MVP are quick to point out that (very simple) MPV examples remove the ability for ASP.NET to use session and caching. How do you access context-specific information if presenters can't have a reference to anything downstream (i.e. System.Web or System.Windows.Forms)? The presentation layer should provide a way to maintain application state.

======================

Here is a basic Contact Us Web Form that we'll build with the MVP Pattern.

The first step of MVP is to create a contract. We're going to use a .Net Interface for that. Create a file called IContactUs.cs and use this code. This is our VIEW in the MVP.

public interface IReaderContactUs
{
string Name { get; }
string Email { get; }
string PhoneNumber { get; }
string Message { get; }
string Result { set; }
}



The interface is like a blue print to a house. No implementation, just directions. This interface says that we have to be able to "GET" Name, Email, PhoneNumber, and Message. And that we have to be able to "SET" a Result string.



Next we need a Presenter. The presenter is the worker bee. The presenter actually does the work. Interestingly, the Presenter knows **NOTHING** about the UX. Repeat **NOTHING**. The presenter is usually in a different class library, and only referenced from the UX code. In order to enforce out contract (the .net interface we just created) we want to only be able to create a presenter, with an instance of the Interface. To do this, notice that our only constructor takes a single param that is the interface. Here is the code for our presenter; named ContactUsPresenter.cs



public class ContactUsPresenter
{
private readonly IReaderContactUs view;

public ContactUsPresenter(IReaderContactUs view)
{
this.view = view;
}

public void ProcessForm()
{
//do something - save it, send it, process it
//in this case, just modify the UI, so we
//know it's running.
//This is where you would normally make a call into the model


        StringBuilder sb = new StringBuilder();
sb.Append(string.Format("Name : {0}<br />", view.Name));
sb.Append(string.Format("Email : {0}<br />", view.Email));
sb.Append(string.Format("Phone : {0}<br />", view.PhoneNumber));
sb.Append(string.Format("Message : {0}<br />", view.Message));
view.Result = string.Format("<h1>Success</h1>{0}<hr />", sb);
}
}


Finally we get to the code behind of our Web Form. Our web form Implements the Interface. All this means is that our web form has to be able to "GET" Name, Email, PhoneNumber, and Message. And that we have to be able to "SET" a Result string. Notice the appropriate Get / Set routines that wrap around the asp.net server controls.



Notice that we have a private ContactUsPresenter, that doesn't get instantiated until the OnInit event. This is because we have to send in an instance of the interface, which is the this keyword. Then when the button is clicked, the presenter.ProcessForm(); is called to do the work.



public partial class ContactUs : UserControl, IReaderContactUs
{
private ContactUsPresenter presenter;

public string Name { get { return NameTextBox.Text; } }
public string Email { get { return EmailTextBox.Text; } }
public string PhoneNumber { get { return PhoneTextBox.Text; } }
public string Message { get { return MessageTextBox.Text; } }
public string Result { set { ResultLabel.Text = value; } }

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
presenter = new ContactUsPresenter(this);
}

protected void Page_Load(object sender, EventArgs e)
{
}

protected void SubmitContactButton_Click(object sender, EventArgs e)
{
presenter.ProcessForm();
}
}



=========

You may need to check out MVP Pattern in Web Client Software Factory as well. This will give you a complete guidance to implement MVP Pattern in your web application




http://www.codeplex.com/websf/Wiki/View.aspx?title=MVP_landing_page&referringTitle=bundles