Jan 31 2006

Convert UserControls to Custom Controls

I found a nice article today on MSDN titled as:
Turning an .ascx User Control into a Redistributable Custom Control

I will summarize as much as possible of that article, since it is really a valuable one.

It talks about creating your own UserControls, then converting them into CustomControls.

Create a New Web Site in Visual Studio 2005 (I guess it should work in VWD too, haven't tried it). Name it WebUserControl (Namespace Name!!!)

  • Add a new Web User Control
  • Design the control the way you want. For the same of this post, I created this simple user control shown below, you can use either Code-Beside or Code-Inline:
<%@ Control Language="C#" ClassName="WebUserControl.HelloWorld" %>

<script runat="server">

    protected void btnSubmit_Click(object sender, EventArgs e)
        this.lblMsg.Text = Server.HtmlEncode(this.txtMsg.Text);

<strong>Hello World Custom-User Control<br />
<br />
Enter Your Name:
<asp:TextBox ID="txtMsg" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" /><br />
<br />
<br />
<asp:Label ID="lblMsg" runat="server"></asp:Label>
  • Compile the control, and then add it to the default.aspx page that came with the website upon its creation. Make sure it works, and then delete that default.aspx page.
  • Now we need to publish the usercontrol, why? In ASP.NET 2.0, every aspx page or ascx file, will be converted to its own DLL file either through precompiling or at run time. In this example, we will publish the website, which requires precompiling the website, and this generating the DLL that resembles the user control under test.
    • Go to Build --> Publish Web Site
    • Type in the Target Location, where the precompiled files shall be placed.
    • Deselect the *Allow this precompiled to be updatable*, why? In the updatable mode, only the code-beside will be precompiled and not the ascx file itself. In our case we need both to be in one DLL.
    • Select *Use fixed naming and single page assemblies*. "This will gurantee that your user control will be compiled into a single assembly that will have a name based on the ascx file itself ..."
  • Now, the user control is precompiled. Create a new website, right click the application, Add Reference, choose the DLL just created.
  • On an aspx page, ad the following below the page directive:
<%@Register TagPrefix="bhaidar" Namespace="WebUserControl" Assembly="App_Web_helloworld.ascx.cdcab7d2"%>

The Namespace is the same as the Namespace in which the UserControl was created.
The Assembly, is the name of the DLL file generated

  • Inside the page body, add the following control:
<bhaidar:helloworld id="MyUC" runat="server"/>

Although this method made your user controls become custom controls yet, the custom controls won't have any desing time view and this is really a loss!!!

Hope you enjoyed this post and found it beneficial.





Jan 31 2006

Download Visual Studio 2005 Code Snippets

You can now download a set of Code Snippets to use in your C# development.

Please check this link for more information: Visual Studio 2005 Code Snippets





Jan 31 2006

LebDev.NET UserGroup - Next Community Night - Thursday, February 2 - 2006

Category:[email protected] @ 18:33

I would like to invite, all those who are capable of attend, to the 8th Session out of the series of the Community Nights held by Microsoft Beirut Offices and the LebDev.NET UserGroup, which is the first Lebanese UserGroup.

The topic of this coming session is:  Introduction to Windows Workflow Foundation

The session will be presented by:
Mr. Tarek Bohsali, Senior Consultant, Microsoft Consulting Services.

To have more information on this session, please visit our user group website at:



Hope to see you all,

LebDev WebMaster


Jan 30 2006

Extend String.IndexOf() &amp; String.LastIndexOf() Methods

Category:[email protected] @ 09:31

I have always found a limitation in the string.IndexOf() and string.LastIndexOf() methods in a sense that, you can either get the position of the first occurrence or the last occurence of a certain value within a given string.

What if we want to get the position of a value at the second occurrence or third or fourth, etc ...?

The solution is simple, look at the following C# function:

public int PositionOf(string strString, string value, int occurrence)
    int num1 = -1;

    for(int i=0; i<occurrence; i++)
        num1 = strString.IndexOf(value,num1+1);

    return (num1);

What this simple function does, is to return the position of a value within a given string at any occurrence of choice.

A great thanks to my colleague Ms. Samar Khayat who shared her ideas while working on this function in our office work.




Jan 27 2006

Add a Custom Link in CS 2.0 Beta 3

Category:[email protected] @ 16:37

In reference to a post on the http://www.communityserver.org forums, on how to create a custom section in CS 2.0 beta 3, I decided to write this post here.

1- Open SiteUrls.config, in the Locations section, add the following no matter where you places them preferably before the weblogs location.:

     <location name="CustomPage" path="/CustomSection/" exclude="true" />

2- In the Navigation section, add the following according to your own order you want:

      <link name="CustomPage" text ="Custom Link" navigateUrl="/cs/CustomSection" />

You must be aware that I have installed CS on http://localhost/cs

3- Create a new folder called CustomSection inside the web folder.

4- Add a page called default.aspx page.

5- Now you want to show some content on the page right? You need to follow a certain Master usercontrol. Go to /Themes/default/Masters/ create a new text file name it CustomPage.ascx.

6- Open the HomeMaster.ascx usercontrol, copy its content and paste them in the new CustomPage.ascx.

6- Make sure you change the following line in the CustomPage.ascx:

<CS:SelectedNavigation Selected = "Home" runat="Server" id="Selectednavigation1" />

Make sure you remove the word Home and replace it with the name of the custom location in SiteUrls.config, and in this case, rename it to: CustomPage. This is done so that, once you are in the Custom Section, its link will be highlighed to differentiate where you are now.

7- Now that you created the Master control, you need to open the default.aspx page in the root folder i.e. (/cs/default.aspx), copy its content and paste it in the default page inside (/cs/CustomSection). You can use the code below to show all the different available sections inside a page, that you can have, at least that is what I was able to find out.

<%@ Page SmartNavigation="False" Language="C#"  enableViewState = "false" %>
<%@ Register TagPrefix="CSD" Namespace="CommunityServer.Discussions.Controls" Assembly="CommunityServer.Discussions" %>
<%@ Register TagPrefix="CS" Namespace="CommunityServer.Controls" Assembly="CommunityServer.Controls" %>
<%@ Register TagPrefix="Galleries" Namespace="CommunityServer.Galleries.Controls" Assembly="CommunityServer.Galleries" %>
<%@ Register TagPrefix="Blog" Namespace="CommunityServer.Blogs.Controls" Assembly="CommunityServer.Blogs" %>
<%@ Import Namespace="CommunityServer.Components" %>
<%@ Import Namespace="CommunityServer.Discussions.Components" %>
<%@ Import Namespace="CommunityServer.Blogs.Components" %>
<%@ Import Namespace="CommunityServer.Galleries.Components" %>

<CS:MPContainer runat="server" id="Mpcontainer1" ThemeMasterFile = "CustomMaster.ascx" >

 <CS:MPContent id="lcr" runat="server" >
  <div class="CommonSidebar">
   <cs:ContentPart runat = "Server" contentname="featuredLCP" id = "featuredContentPartLCP">
    <div class="CommonSidebarArea">
     <h4 class="CommonSidebarHeader">Left Area
     <div class="CommonSidebarContent">
      <p>You Place the Left Side content here!!</p>

 <CS:MPContent id="bcr" runat="server">
  <div class="CommonContentArea">
   <div class="CommonContent">
   <cs:ContentPart runat = "Server" contentname="welcomeBCP" id = "welcomeContentPartBCP"
      text="<h2 class='CommonTitle'>Welcome to Community Server! </h2><IMG src='http://communityserver.org/utility/images/showcase_sites.gif' align=right> <a href='http://communityserver.org/r.ashx?3' target='_blank'>Community Server</a> is the award winning platform that enables you to quickly and easily create online communities. <p>Community Server is a collaboration platform and includes: discussions, blogs, content management, photo gallery, file gallery, user management tools, advanced permissions system, extensible theme engine, and much more.</p><p>Community Server is a shared source platform developed, maintained, supported-by, and licensed by <a href='http://communityserver.org/r.ashx?2' target='_blank'>Telligent</a>. Telligent additionally offers services for helping customize, host, and manage your Community Server system.</p>" />

 <CS:MPContent id="rcr" runat="server" >
  <div class="CommonSidebar">
   <cs:ContentPart runat = "Server" contentname="featuredRCP" id = "featuredContentPartRCP">
    <div class="CommonSidebarArea">
     <h4 class="CommonSidebarHeader">Right Area
     <div class="CommonSidebarContent">
      <p>You Place the Right Side content here!!</p>
 <CS:MPContent id="BodyFooterRegion" runat="server" >
  <div class="CommonSidebar">
   <cs:ContentPart runat = "Server" contentname="featuredFCP" id = "featuredContentPartFCP">
    <div class="CommonSidebarArea">
     <h4 class="CommonSidebarHeader">Footer Area</h4>
     <div class="CommonSidebarContent">
      <p>You Place the Footer content here!!</p>

At least this will show you a page similar to the one here.

Hope this helps you out. I am always ready for any comment or question. Above all, if you guys from CS team find anything wrong, or anything can be improved in my post to make creating custom sections in CS esay, please do comment or contact me directly.

Thank you all,
A special thanks to Scott Watermasysk



Jan 27 2006

Upgraded my website to CS 2.0 Beta 3

Category: General | General[email protected] @ 11:01

I have just finished upgrading my website to CS 2.0 Beta 3.

I have also played around a bit with CS files and created a Custom Link, to show how easy it is to work with a CS website.

Although it is not yet a CMS, however, it could be used now for a community site very easily, specially that adding new links and sections is not a tough thing to do.

Hope you enjoy the stay,



Tags: ,

Jan 25 2006

How to publish Community Server 1.1 remotely?

Category: Community Server[email protected] @ 10:21

In a previous post, we have seen how to install CS 1.1 on a local machine.

Now it is time to upload our installation to our own web space. We will be installing CS 1.1 inside a folder called *cs*, so now you can have the CS 1.1 home page @: http://mywebsite.com/cs/

  • Copy the web folder where you had your CS 1.1 installation on your local machine, suppose it is called *Web*, to the root of your web space
  • Create a Virtual Directory called cs that points to the folder called Web thay you just have uploaded to your root directory of the web space
  • Make sure the database has been upload successfully, how to upload it? Depends on the hosting company you are working with
  • Open the table called cs_Sites, you will find inside it a record that has a SiteUrl of *localhost/cs*, change this to something as *mywebsite.com/cs*

That is all, you have now a working version of the CS 1.1 on your web space.





Jan 24 2006

Community Server 2.0 Beta 3 is in town !!!

Category:[email protected] @ 21:54

You can now download the CS 2.0 Beta 3 as:

Windows and Web Installers.




Jan 24 2006

The Dream - Episode 3

Category:[email protected] @ 19:45

I promised you to inform you on my dream every now and then.

I have been working on it for around 4 continious days.

I got some sickness yesterday and still till today at home because of the illness. However, nothing can and will stop me from reach the dream and making it a truth.

I consider myself still on the mid of the road, but I will arrive soon ;)

Keep an eye here!!




Jan 23 2006

Provider ToolKit Configuration Utility

Category:[email protected] @ 20:51

A Code Template for Building a Provider Based Feature has been published lately on the Microsoft ASP.NET Developer Center.

This is a Provider ToolKit that gives developers a ready made template for a Provider Model for him/her to customize as the need is.

There is a readme.txt file inside the downloaded Provider ToolKit to help you configure the toolkit to make it work for your application.

If you don't want to read that readme file, then download the utility I created to configure for you that Provider toolkit.

Normally, what you have to configure in that Provider ToolKit is the:

  • Provider Name
  • NameSpace
  • Type of Provider: Microsoft Access, Microsoft Sql Server, Oracle, or MySql

In all the files accompanying the toolkit.

After confgurating that toolkit, you will have a set of classes constituting your Provider Model classes which are:

  • MyTestProvider: Which is the base class including all the abstract methods.
  • MyTestConfiguration: A class responsible to get all the configuration properties of that provider from the Web.config file.
  • MyTestProviderCollection: A class responsible to hold the configurations for each provider configured in the application inside the Web.config file.
  • (Sql-Access-MySql-Oracle)MyTestProvider: Is the concrete implementation of the methods inside the MyTestProvider.
  • Configuration Sections in the Web.config

In order for you to go through each of the above files and change the names and file names, it would take like 30 to 60 minutes to do so.

The tool I created:

All you have to do is enter the Provider Name (without the*Provider word*), enter the NameSpace (can be left empty), choose an implementation out of the 4 available.

It will do nothing but customize the Provider Toolkit as you want, so no more needed to waste the 30 - 60 minutes trying to configure the files in the Provider toolKit.

Hope this utility helps you. you can download it from the DownLoads Section of my website. I have placed both the code and the executable application.

Happy Dot Netting!