Building A BlogEngine Extension, ModeratedComments Extension
If you are BlogEngine.Net fan, then you should heard or used BlogEngine.Net Extensions; the extensibility feature in BlogEngine.Net. My story with Extensionsstarted just last week. I enabled the comment moderation setting on my blog. And I faced a small issue, I wanted a page to view all moderated comments -waiting for approval-. I proposed that to my friend Amr, he suggested to me to have a look at BlogEngine.Net Extensions.
The Story:
Well, the story was that I wanted to view all unapproved comments on my blog. There was only one solution in my mind before Amrsuggest to me to use BlogEngine.Net Extensions. That solution was to add new methods to exiting APIs or use the existing ones. I liked the idea of using existing ones, but the issue is that I will have to loop through all posts to find out if any as unapproved comments. And of course I didn't like the idea of adding new methods to existing APIs because it is just not acceptable at the time being, I am not one of BlogEngine developer's team, so will be hard for me to integrate my code in the upcoming releases.
The Extension Solution:
"Extensions allows you to write a class that can hook up to all the various events that are exposed in the application in a very simple manor" -Creating Extensions on BlogEngine Wiki-. Yes this sound like something to me. I need every time a comment is added to my blog to bookmark the post as it has pending comments waiting for approval. So I will handle Post.CommentAdded event and bookmark the post. Later, I'll build a page to view bookmarked posts and retrieve their moderated comments. To Bookmark a post, I just used simple XML file to store the unique identifier of the post.
More...
Building a grouping Grid with GridView and ASP.NET AJAX toolkit CollapsiblePanel
UPDATE: I've posted an update to this post to apply on demand loading of Details data using ASP.NET AJAX PageMethods. I'm demonstrating the usage if CollapsiblePanelExtender client events on the new post. Check it out.
I admit, Matt Berseth is really inspiring me! Few days ago I pass through 2 of his great posts:
The first one is pure design tips one which I used for making good presentation of my demo here. The 2nd post is actually the idea.
Here I'll do the same idea Matt presented in his post, but I'll user ASP.NET 2.0 simple stuff plus ASP.NET AJAX Toolkit CollapsiblePanel control.It is required that you have ASP.NET AJAX Extensions installed to be able to run the sample code.
I'll not go through the presentation tips mentioned in Matt's post, I'll just show my technique to implement grouping idea with GridViews and CollapsiblePanel along with SqlDataSource which of course can be replaced with ObjectDataSource. I should mention that I'm using same style sheets provided in Matt's sample code along with images [View Demo]. More...
Building GridView With ASP.NET AJAX Enabled Control with Script#
Introduction:
I was thinking of building ASP.NET AJAX Supported controls inorder to practice both ASP.NET AJAX extensions as well as Script# tool.
Actually I liked the work done by Matt Berseth regarding ASP.NET AJAX very much. So I decided to use his ideas, convert them with Script# and add extra view things. So 99% of this post credit returns to him, I will just show how to use Script# and work around few things [Demo].
Original Reference:
I picked a control Matt built as GridView Extender (Behavior).And he provided few posts about and here they are:
Simply the idea is to improve the look and feel of the simple GridView with extra styles. For example when hover over a grid cell/row or when click on a row. The control was built as AJAX Extender also known as Behavior that can be applied on a GridView. More...
Applying localization From MasterPages
The scenario here is I want to apply localization to my web application and place language selection on MasterPage. I have made my own solution and applied this with assistance of cookies. View demo.
I'll demonstrate that in my sample. The sample has a MasterPage bellow is a snippet from its ASPX code:
1: <form id="form1" runat="server">
2: <div>
3: <asp:DropDownList ID="cmbCulture" runat="server" AutoPostBack="True"
4: OnSelectedIndexChanged="cmbCulture_SelectedIndexChanged">
5: <asp:ListItem Value="en-US">English</asp:ListItem>
6: <asp:ListItem Value="ar-EG">Arabic</asp:ListItem>
7: <asp:ListItem Value="de-DE">German</asp:ListItem>
8: </asp:DropDownList>
9: <asp:ContentPlaceHolder ID="cph" runat="server"/>
10: </div>
11: </form>
Simply when the user selects his language from the DropDownList the page post backs and change the language. More...
WebResourceAttribute And VB.NET, Not Like in C#!
Refering to my previous post "Working with System.Web.UI.WebResourceAttribute". During surfing in ASP.NET forums I noticed a question about this issue! and in the question it is mentioned that the way I descriped didn't work. I noticed also that the guy was using VB.NET not C# on which I was working on!!
The deference, or the issue came up because C# & VB.Net treat or compile resources in deferent ways -this is my own observation-. Return to the issue post on ASP.NET Forums to know what was exactly the problemand how it was resolved.

Working with System.Web.UI.WebResourceAttribute
You may've heared about new ASP.NET 2.0 System.Web.UI.WebResourceAttribute class. It defines the metadata attribute that enables an embedded resource in an assembly. It is valid only when used on assembly declarations and it is used to enable a specified embedded resource in an assembly for use as a Web resource.
For example, suppose you are building a web server control, or custom HttpHandler that would render some javascript "js" files and may few images etc...
Where you would store these files "resources"?! The answer is you can embed them in your assembly and reference them as web resources from your code.
To register a resource as WebResource you would use this line of code, you can do that in AssemblyInfo file:
[assembly: System.Web.UI.WebResource("imagename.jpg", "image/jpeg")]
For more information about WebResource parameter, please return to MSDN, currenlty I can mention that the 1st on is the resource name, and the 2nd one is the content-type of the resource, in our case it is an image so the content type is image/jpeg. If your resouece file is javascript, then the content-type would be text/javascript
And you can reference your resource using ClientScriptManager class through Page.ClientScript Property as the following
string resUrl = this.Page.ClientScript.GetWebResourceUrl(typeof(YouControlType), "imagename.jpg");
Now use your resUrl to display your image!.... BUT WAIT, this is not going to work!!
If you followed the MSDN code while you are VS.NET this is not going to work at all, your image or your resource file never appear.
Here are the Rule:
- You should know your Assembly default namespace.
- Recognize where exactly your resource file located in your project, "Its Path"
- Define the correct resource name.
Suppose your default namespace is Moses.WebControls, while your resource file name is ComboBox.js, this file is located on a folder named Resources/Scripts in your project -Dont care about your project name or assembly name, just focus on your Default namespace name-.
Now your resource file should be name "Moses.WebControls.Resources.Scripts.ComboBox.js".
The rule simpley is [Default namespace].[Resource Path from the project root -replace '/' with '.' of course-].[Resource FileName]
So you'll register your WebResource as the following:
[assembly: System.Web.UI.WebResource("Moses.WebControls.Resources.Scripts.ComboBox.js", "text/javascript")]
And you can get your resource URL as the following:
string resUrl = this.Page.ClientScript.GetWebResourceUrl(typeof(YouControlType), "Moses.WebControls.Resources.Scripts.ComboBox.js");
Hope this would help somebody

Tip: Generating Local Resource Files
As I was working on multingual User Interface project; it was needed to generate resource files for all aspx & ascx files.
I knew that VS.NET 2005 has a local resource file generator. But it was weird when I select my ASPX page or user control and go to Tool menu and find that there are no Generate Local Resources command on the menu!
It didn't take so much time, I found the solution on ASP.NET Forums. It was simple: "he menu 'Tools > Generate Local Resources' is available when you display an aspx page or ascx". Also you must switch to design veiw before you Generate your local resources.

3 Parts ASP.NET WebParts tutorial
2 years ago, I wrote 3 parts ASP.NET WebParts tutorial. Bellow are summary of each parts and links to original tutorial on www.C-ShareCorner.com
- Creating a Simple WebPart Page and use WebServer controls as WebParts
Introduction:
Portal web sites such as MY MSN and MSN Spaces, often organize their data into discrete units that support a degree of personalization. Information is organized into standalone parts [WebParts], and users can rearrange those parts to suit their individual working styles. Such personalization also lets users hide parts that contain information in which they have no interest. What's more, users can save their settings so that the site will remember their preferences the next time they visit the site. In ASP.NET 2.0, you can now build web portals that offer this kind of modularization of information and personalization using the new Web Parts Framework.
Scope of this Tutorial:
Here we will see how to add web parts to a web part page. Developing advanced WebParts from scratch is out of this tutorial scope. This tutorial also may has subsequent tutorial that explains more about Web Parts Framework.
Assumptions:
This tutorial assumes you are familiar with Data Access Controls and Data Binding Controls such as SqlDataSource and GridView. Also it requires SQL Sever 2005 Express Edition and Visual Web Developer. If you don't have SQL Server Express 2005, install ASPNETDB in your SQL Server instance using aspnet_regsql tool. and configure your application to use this instance as your personalization provider.
How to create WebParts Page:
To create a WebParts Page, you need to work with a specific ASP.Net 2.0 Controls: - WebPartManager Control, which manages all Web Parts controls on a WebParts Page and must be the first control that you add to the page.
- WebPartZone Control, which contains and provides overall layout for the Web Part controls that compose the main UI of a page. This control serves as an anchor for Web Part controls. Multiple controls of this control forms the WebParts Page. Read more....
- Working with WebParts Page, WebPart Zones & WebParts
Introduction:
This tutorial considered to be the second part of the first tutorial Creating a Simple WebPart Page and use WebServer controls as WebParts. Here we will see how can we remove and add WebParts during run time, adding personalizable properties to your WebParts and modifying there values also in run time.
WebPart Zones:
There are 4 types of WebPart Zones. Zones is used to host (anchor or dock) WebParts. In the previous tutorial we had a look at WebPartZone. At this tutorial we will have a look at the other another two WebPart Zones, CatalogZone & EditorZone. Read more...
- WebParts Communication: How WebParts on a page communicate with each other
Introduction:
In this tutorial we will describe how to make WebParts on a WebParts Page communicate with each other. So will see how to use ConnectionsZone and how to enable WebParts to talk to each other by connecting them.
Assumptions:
This tutorial assumes that you know how to work with web forms, creating user controls and connecting to data sources using SqlDataSource Control. Also you should know how to use WebPartZone control and to know what are WebParts and WebParts Pages. Read more...

My first Wiki experiance, My first Wiki contribution
Last year (2007) on March I joind CSharp-Online community. It is Wiki Media based community web site. Actually that was the first time to use Wiki. I was always watching Wikies but never touch them. I liked that Wiki. It is easy and smart or may be I'm a dump.
Anyway, I had finalized my first contribution on there and it is about Creating Custom ASP.NET AJAX Client Controls. I've built this article on top of this tutorial
"Adding Client Capability to a Web Server Control Using ASP.NET AJAX Extensions".
Hope it will be useful for someone.

ASP.NET 2.0 AJAX Timer Hacks! How to Pause ASP.NET AJAX Timer
UPDATE:
Matt Berseth posted a detailed information about this tip on his post Bug Bash: Enabling/Disabling the ASP.NET AJAX Timer using the Control's Client Side API. Much clearer and explained in details. [May 08, 2008]
----------------------------------------------------------------------------------------------------------------------------------
from about 2 weeks I wrote an article about how you can use ASP.NET 2.0 AJAX Timer control in a real world scenario side by side with RssToolKit.
The idea it to display RSS feed from deferent location in cycle using ASP.NET AJAX Timer. I also had an idea of pausing the Timer when the user move his mouse over the update-able area "Group Box that display feeds inside it". Of course this should be down from client side.
I searched the documentation for Client Side APIs related to the AJAX Timer control but I didn't find any. I had to hack inside AJAX Timer client library downloaded with ASP.NET AJAX Extensions, and I found what I want.
First I though that by setting client side enabled property using set_enabled(false) of the AJAX Timer I could get what I want; actually I was wrong, this will not pause the Timer.
Dig deeper, but not for too long, I found 2 methods _startTimer() and _stopTimer(), those were excatly what I was looking for.
bellow is a sample client code of how you can use these 2 methods:
1: function startTimer() { var timer = $find("<%=ajaxTimer.ClientID%>"); timer._startTimer(); } 2: function stopTimer() { var timer = $find("<%=ajaxTimer.ClientID%>"); timer._stopTimer(); }
The above code assuming that you have an AJAX Timer control on the page named ajaxTimer. Call these method from your client side code, or add them as event handlers on your target elements.
I don't know why these are not documented, or we are not supposed to use them?! Actually I don't know. I thought that after using these methods the browser will cause a problem regarding client scripts, but both Opera and IE worked just fine without any problem. Also I didn't notice any slow down or hanging in both browsers.
Hope you find it useful.

How to build Multi-Language Web Sites with ASP.NET 2.0 and Visual Studio.Net 2005
Last year I wrote an article about how to build multi-languange web sites with ASP.NET 2.0 and Visual Studio.Net 2005. This is a bookmark to the articles (C#,VB.NET) [poste migrated from old blog]
Introduction: In order to reach international markets through the Internet, supporting different cultures through our applications is essential for being successful. The .NET Framework 2.0 as well as 1.x comes with an integrated infrastructure for creating international applications. Basically, the CLR supports a mechanism for packaging and deploying resources with any type of application. The CLR and the base class library of the .NET Framework come with several classes for managing and accessing resources in applications. These classes are located in the System.Resources and System.Globalization namespaces. Here we will explore the necessary details for working with resources in ASP.NET applications and for creating international ASP.NET applications based on embedded resources and the integrated localization support.
Assumptions: This article assumes that you already know how to build web forms and to use controls and validation controls.
Localization and resource files: Localization support in .Net Framework 2.0 in general and in ASP.Net 2.0 specifically become much more easier and brings fun during localization process. Usually resources are created for every culture the application should support. More specifically, each Web Form -Page- in your web site should have a resources for every culture -language- it should support. For example:If you have a web form with name default.aspx and your web site support English, German and Arabic, then you should have 3 resource files for each culture. The CLR defines a behavior for finding culture-specific resources. With that said, every set of resources has to define a base name that is specified through the first part of the name of the resource file. The second part of the name defines the culture. If the culture portion in the name is not specified, the resources defined in the resource file are used as default resources. For example:Your page name is default.aspx., you have 3 resource files as mentioned earlier, each one resource file should be named as:default.aspx.en-US.resx, default.aspx.de-DE.resx and default.aspx.ar-EG.resx. Not here that we are using United States English, German's Gemran, and Egyptian's Arabic. You can use general English or general German or general Arabic like this:default.aspx.en.resx, default.aspx.de.resx and default.aspx.ar.resx. Also you can use another specific culture like using Switzerland German culture this way: default.aspx.de-CH.resx. For list of supported cultures in .Net Framework return to MSDN.
Read the complete article at C-SharpCorner.com
Read the VB.Net version as VBDotNetHeaven.com
