Sponsored
Tuesday, December 9, 2008
FIX: HTML documents may not be displayed correctly in IIS 7.0 on Windows Vista
Wednesday, October 1, 2008
More About Color Picker ASP.NET AJAX Extender
I have published an article on Code Project about the Color Picker ASP.NET AJAX Extender. Please read it there.
Friday, September 26, 2008
Color Picker ASP.NET AJAX extender control
I was looking for a client-side color picker control and found it extremely difficult to find something that would satisfy to my requirements. I have found plenty of pure JavaScript controls written with various levels of proficiency and there was even one ASP.NET color-picker control that I almost liked but still my major requirement was not satisfied: I was looking for AJAX .NET Extender control - easy to use and based on a solid and proven platform.
So, I have researched what other color picker controls do and decided to write the one myself that I would base on Microsoft AJAX .NET platform. After some considerations I've decided to go even further and build an AJAX Control Toolkit Extender control.
As an example I took an AJAX Control Toolkit Calendar extender and in my Color Picker extender control I also internally used another AJAX Control Toolkit control: Popup extender.
Now, what are the advantages of implementing a client control as an ASP.NET AJAX extender?
- You use ASP.NET page mark-up to render the control content to the browser.
- No need to manually inject JavaScript, HTML and other resources.
- You develop JavaScript code in a standalone file leveraging ASP.NET AJAX framework and Visual Studio intellisense abilities.
- JavaScript per se is very well structured, easy to read and debug.
- Many of the hassles of JavaScript client coding such as cross-browser compatibility, event handling, asynchronous calls are taken care of by ASP.NET AJAX framework.
So, I have spent a few days coding the control and finally it's out there. I have created a Codeplex project for it so if you are interested just go there and download the control and a Demo Web site.
Now, just a few more words about the extender. First, this is how it looks:
Second, it's extremely easy to use. The extender attaches to an ASP.NET TextBox server control and to an optional button that can open a popup window and an element that samples a selected color in the background. User selects a color by clicking on a colored area. Below is a code example of using an extender on an ASP.NET page.
<asp:TextBox ID="TextBox1" runat="server"
Columns="7" MaxLength="7"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/Images/icon_colorpicker.gif" />
<cdt:ColorPickerExtender ID="cpe" runat="server"
TargetControlID="TextBox1"
SampleControlID="ImageButton1"
PopupButtonID="ImageButton1" />
Feel free to download the extender from the Codeplex, try it and post any comments or suggestions on the Codeplex project page.
Update 2020
Recently, I've visited the old and now archived CodePlex page for the ColorPickerExtender (https://archive.codeplex.com/?p=cpe) and found out that back in the day Microsoft had included that control on the official ASP.NET site (https://docs.microsoft.com/en-us/aspnet/web-forms/overview/ajax-control-toolkit/colorpicker/using-the-colorpicker-control-extender-cs). What a nice thing! Encouraged by this finding I've decided to resurrect the CPE and port it over to Angular, which is currently my favourite client-side framework. I will be introducing a new project on Git some time at the end of 2020, so stay sharp!
Friday, September 19, 2008
Axialis IconWorkshop™ Lite for VS 2008
It's been a little buzz around this free VS2008 plug-in but it really is true and there is a free version of the Axialis IconWorkshop for VS2008. If you want to download and install it please use the direct link because you won't be able to find this page on the Axialis web site. Though to be honest its functionality is not anyhow better then Paint.Net which is also free but fully-functional. Besides being called a VS plug-in it opens up in a separate window. But see for yourself.
Monday, September 15, 2008
Working with VEColor class of VirtualEarth SDK
If you ever wanted to set a color for a custom VEShape object of type polyline or polygon than you must be familiar with the VEColor class that is used to represent a color in VirtualEarth SDK.
I am sure there are reasons behind of the design of the VEColor class, but for those who are used to a standard Web color representation in a form of 6-digit hexadecimal number it's kind of weird to provide 3 integer number in order to construct a color.
So I was in a search for some convenient ways of converting between VEColor and standard Web color and first place I looked through was of course the VirtualEarth Map control because I thought that the VE developers themselves would need a way to perform the same exercise. No surprise there is a couple of non-documented VE objects to support such conversion technique.
Here is a code example of using those objects:
// Create a convertor class
var converter = new VEHexStringToColor();
// Converter returns an instance of a VEColor class
// Transparency value is always set to 1.0
var veColor = converter.Convert("aabbcc");
// Adjust transparency value
veColor.A = 0.7;
// Convert VEColor to a string with a leading '#'
var webColor = VEColorToHexString(veColor);alert(webColor);
Both objects are available on the page after you reference a VE Map control v6.1. Of course there is no guarantee of any support of those objects in any future versions of the VE Map control so use it at your own risk and have fun.
Tuesday, June 17, 2008
Scalable CSS for Ajax Control Toolkit Tabs
If you use Tabs control from AJAX Control Toolkit library you may have noticed that the default CSS definition provided with the control does not display properly when you increase font size on a page, that is the default CSS is not scalable.
Since Tabs allows you to override CSS it's quite easy to fix a problem. Just grab a correct CSS file with the set of images and assign a CssClass property a new class name:
<ajaxToolkit:TabContainer runat="server" CssClass="myTabs" ...>
Now it looks more appropriate:
Friday, May 30, 2008
Access DataItem declaratively using data binding syntax
Sometimes there is a need to access a DataItem object of a data-bound server control. It usually happens when you want to display the value of the bound object as a whole instead of its property.
Standard data binding syntax assumes using a Bind(string name) or Eval(string name) methods in the context of data binding expression where name is a name of a property of the DataItem object. But what if the data item if of type that does not have properties like System.String for examples?
In this case there is another method that you can use: GetDataItem(). It will return to you the current instance of the DataItem object that you can use.
Syntax example:
<%# GetDataItem() %>
That sort of syntax can be used even for DataSource properties in complex nested databound template controls.
Last-Modified HTTP header on ASP.NET page
"Last-Modified" HTTP header is an important part of every web page since it helps browsers to cache pages' content locally and thus save HTML traffic. It is also used by internet search engines in order to determine the relevance of the pages' content and thus improves pages' indexing.
By default, a standard ASP.NET page does not include a "Last-Modified" header in the output HTML. One of the possible explanation for such behavior is that an ASPX page is considered dynamic by nature meaning that its content might be updated every time the page is requested. It is true in many cases for data-driven and interactive pages but most of the dynamic web sites also contain pages that are updated relatively rare or static.
So, when does it make sense to add a "Last-Modified" header to the page? First candidates usually are data-driven pages that display information from some sort of content storage systems (databases, files, etc.) and that information changes but not very frequently so there is a possibility that the same content may be viewed many times. Other apparent candidates are static pages even if they are data-driven but their content does not change for the lifetime.
What are the pages that do not need the "Last-Modified" header? Obvious candidates are interactive pages and pages that displays user session related data.
ASP.NET provides two methods to set the "Last-Modified" header on the page. Both of them belong to the HttpCachePolicy class and are accessible through the Cache property of the Response object:
Response.Cache.SetLastModified(DateTime date);
Response.Cache.SetLastModifiedFromFileDependencies();
The first method takes a DateTime parameter that allows you to apply some algorithm for calculating the Last-Modified date of the page, for instance based on information from a database. The second method will calculate the date stamp automatically based for instance on the assembly build date. For the second method you can also include additional file dependencies in date calculation using
Response.AddFileDependancy(string filename);
For instance if a page displays a content of a static XML file you could include that XML file in the dependency and the "Last-Modified" header's value would be updated based on that file's "Date Modified" attribute.
Friday, May 23, 2008
ScriptManager vs. ToolkitScriptManager
Introduction
ScriptManager is a special ASP.NET server control that should be placed on a page before you can use any of AJAX.NET enabled controls. The same rule is true for the AJAX Control Toolkit controls: they all require a ScriptManager on the page. While AJAX Control Toolkit controls work perfectly fine with the standard ASP.NET ScritpManager the Toolkit includes its own version of the ScriptManager called ToolkitScriptManager that inherits from ScriptManager and is meant to improve some of the ScriptManager's behaviors in particular how it renders out behavior JS scripts. Let's examine how using a ToolkitScriptManager changes a web page's appearance.
Experiment
As a testing example I have created a very simple page consisting of a single Accordion control from the AJAX Control Toolkit library.
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.accHead { border:1px solid #445566;font-size:larger;background-color:#aaa;}
.accHeadSel { border:1px solid #445566;font-size:larger;background-color:#444;color:#fff;}
.accCont { border:1px solid #ccc;padding:5px;}
</style>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="tsm" runat="server"></ajax:ToolkitScriptManager>
<%-- <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>--%>
<div>
<ajax:Accordion
ID="MyAccordion"
runat="Server"
SelectedIndex="0"
HeaderCssClass="accHead"
HeaderSelectedCssClass="accHeadSel"
ContentCssClass="accCont"
AutoSize="None"
FadeTransitions="true"
TransitionDuration="250"
FramesPerSecond="40"
RequireOpenedPane="false"
SuppressHeaderPostbacks="true">
<Panes>
<ajax:AccordionPane ID="AccordionPane1" runat="server"
HeaderCssClass="accHead"
ContentCssClass="accCont">
<Header>Pane Header 1</Header>
<Content>Content 1</Content>
</ajax:AccordionPane>
<ajax:AccordionPane ID="AccordionPane2" runat="server"
HeaderCssClass="accHead"
ContentCssClass="accCont">
<Header>Pane Header 2</Header>
<Content>Content 2</Content>
</ajax:AccordionPane>
<ajax:AccordionPane ID="AccordionPane3" runat="server"
HeaderCssClass="accHead"
ContentCssClass="accCont">
<Header>Pane Header 3</Header>
<Content>Content 3</Content>
</ajax:AccordionPane>
</Panes>
<HeaderTemplate>List of Panes</HeaderTemplate>
<ContentTemplate></ContentTemplate>
</ajax:Accordion>
</div>
</form>
</body>
You may have noticed that right after the form tag there are ScriptManager (SM) control and ToolkitScriptManager (TSM) control on the page but one of them is commented out. Next I run a page from VS 2008 two times: first using the SM and second using TSM, and compare the results.
HTML output and traffic
Let's compare the HTML output of two page versions. See a WinMerge screen shot below that shows the SM version in the left pane and the TSM version in the right pane.
First difference you see is that TSM adds its own hidden field on the page (top right pane) and the next and more important difference is that TSM renders one script reference on the page instead of the five ones that SM does.
Now if we examine the page's traffic with the FireBug we'll see how that changes the traffic: first graph refers to the page using the SM control and the second one when the TSM's at work.
Analyzing the graphs it's easy to see that the TSM does reduce a number of browser's round-trips by combining multiple script references into a single one. This advantage will become more attractive as more AJAX-enabled server controls will be placed on a web page that support script combining. However it is not necessarily true that it will always reduce the page loading time. As you can see when TSM returns a combined script to the page it takes some time to perform a work on the server. Correspondingly the amount of work and consequentially the response time directly depend on the number of scripts to combine (that is a number of AJAX server controls) and the size of the scripts to process (white spaces removal and compressing).
So there is no single recommendation that it's always preferable to use TSM instead of SM. In many cases SM version of a page may work faster then a TSM version of the page. Since it's not that difficult to alter a page for both cases I'd advise to test and compare both versions in your particular scenario before making a decision which one to choose.




