CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Mark DiGiovanni

Software Development and Supporting Technologies

Web Development with SharpDevelop, Web Matrix, and DBGCLR

Visual Studio.NET 2003 makes development a whole lot easier than it ever was before.  But what if you have to develop a web application and you do not have the power of VS.NET 2003 available to you?

I would hate to be without Intellisense (I’m spoiled), debug support, and many of the other features that VS.NET 2003 provides.  There is a way to accomplish this developmental challenge with the following three tools:

SharpDevelop, the free open source .NET IDE, has just been released as Fidalgo RC1 (6/16/2004).  This development environment does not support debugging, or ASP.NET development.  However, SharpDevelop is a great product and it is worth getting excited about.

SharpDevelop’s IDE is very similar to VS.NET 2003; it even has a version of Intellisense.  I felt right at home here.

Web Matrix, the free ASP.NET IDE was released by Microsoft to support ASP.NET development.  This IDE does not support debugging, Windows development, Intellisense, and many other niceties of Visual Studio.NET 2003.

DebugCLR (DbgCLR.exe) is available in the .NET Framework SDK or with Visual Studio.  This tool allows the developer to step into managed code without the need of Visual Studio.NET.

Code snippets in this example are in C#, but can be modified for VB.NET.

Configuring the Solution in SharpDevelop

SharpDevelop has a similar notion of a solution called Combines.  These combines can contain multiple projects. 

I’ve created a project folder for SharpDevelop here: C:\Projects_SharpDevelop and set my default location to this directory from Tools > Options:

Adding a combine:

File > New Combine:

Select a C#, or VBNET Class Library project and call it WebDemo2:

SharpDevelop will create a new class file called MyClass.cs by default.  Delete this file, we will not use it.

This next step is very important.  Set the project output path to C:\Projects_SharpDevelop\WebDemo2\bin.  The bin folder may not exist, so you will need to create it.  To accomplish this, right click on the project, select Project Options > Configurations > Output and set the output path.

Next, add a new file to the project by right clicking on the WebDemo2 project, Add >New File:

Choose a new C# or VB.NET file (depending on what type of Combine you’ve created) and call it MyCodeBehindClass.aspx.cs.

Drop the .aspx from the class name.  This class should inherit from Page.  It should look like this:

Delete the constructor.  It is not needed.

Add the following using statements:

and the following code:

Press F8 to build the Combine.

Configuring the Solution in Web Matrix

Open Web Matrix.

To create a new project which is essentially a shortcut to the directory, click File > New Project and choose Folder ShortCut:

          

Enter the directory path that points to the SharpDevelop Combine: C:\Projects_SharpDevelop\WebDemo2.

You will notice a new shortcut is created in the Workspace sidebar on the right.  Expand the shortcut to see the files that exist from SharpDevelop.

Create a new aspx file.  Right click the shortcut and click Add New File, select ASP.NET Page, and name it MyWebForm.aspx:

 

Next, click the “All” tab at the bottom of the new file, and replace the existing page directive with this one:

This directive can be all in one line.  I wrapped it for this walk through.

Click the “Design” tab at the bottom and drag on a TextBox by expanding the web control's group and selecting the TextBox control from the toolbar to your left.

Click on the play icon on the toolbar or press F5.  Make sure the web path is the same as the Combine location:

I am using the built-in web server provided by Web Matrix (this will display an icon in the taskbar).  You can also use IIS.  This is the main reason we changed the output path of the project.  The web application expects the dlls to be in a bin directory, not bin\debug or bin\release.

The page will run and display the TextBox with the string set in the SharpDevelop class file:

LEAVE THE BROWSER OPEN FOR DEBUGGING

Debugging the Combine

To debug the application, launch DbgCLR.exe.  The quickest way to find this application is to do a search.  If you have VS.NET 2003 installed, the default location is: C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\GuiDebug\DbgCLR.exe.

Open the MyCodeBehindClass.aspx.cs from File > Open > File or CTLR+O.

Set a break point on the following line:

Next, choose the process to step into.  If you are running this example in IIS, choose the aspnet_wp.exe process.  If you are using the Web Matrix web server, choose WebServer.exe.

Click Tools > Debug Processes or CTLR+ALT+P and choose the appropriate process to step into and click Select.  Then close.

Now, refresh the web browser.  You will be taken to the break point:

Why do this?  I always have had this fascination with doing things the hard way.  If you’re anything like me, you might do this just because you can.

Take some time to get familiar with SharpDevelop and Web Matrix.  They both have their own feel.

Additional resources:

SharpDevelop:
http://www.sharpdevelop.com/OpenSource/SD/WhatsNew.aspx
http://www.sharpdevelop.com/OpenSource/SD/Forum/

Web Matrix:
http://www.asp.net/webmatrix/faq.aspx
http://www.asp.net/Forums/ShowForumGroup.aspx?tabindex=1&ForumGroupID=4

--Mark

 



Comments

Erik Springelkamp said:

Hello, I am erik@springelkamp.nl

Just before reading your article, I figured this out by myself and got it working.

However, I didn't add the OnInit event, but just used the OnLoad method to do my page load work.

Am I missing something by doing it this way?

I include my version of my code-behind file in the test-project below:

public class Table: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBoxGroep;
protected System.Web.UI.WebControls.Repeater Repeater1;

protected System.Data.DataSet Gasten = new System.Data.DataSet();

protected override void OnLoad(System.EventArgs e){
string connectionString = "server='(local)'; trusted_connection=true; database='Gasten'";
System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionString);

string queryString = "SELECT [Opgestuurd].* FROM [Opgestuurd] WHERE ([Opgestuurd].[Groep] = @Groep)";
System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();
dbCommand.CommandText = queryString;
dbCommand.Connection = dbConnection;

System.Data.IDataParameter dbParam_groep = new System.Data.SqlClient.SqlParameter();
dbParam_groep.ParameterName = "@Groep";
dbParam_groep.Value = TextBoxGroep.Text;
dbParam_groep.DbType = System.Data.DbType.String;
dbCommand.Parameters.Add(dbParam_groep);

System.Data.IDbDataAdapter dataAdapter = new System.Data.SqlClient.SqlDataAdapter();
dataAdapter.SelectCommand = dbCommand;
dataAdapter.Fill(Gasten);

Repeater1.DataBind();

}

}
}
# March 12, 2005 7:48 PM

Mark said:

Erik,

OnInit fires prior to OnLoad. OnInit ensures that the control is initialized prior to its use.

--Mark
# March 14, 2005 6:43 AM

Chris said:

This is just what I have been looking for. I am wondering if .NET 2 will change any of this. I am especially curions about the express products.
# April 12, 2005 9:52 PM

Rick Booth said:

Thanks for the great walkthrough mdigiovanni. One further (minor) refinement is to add Web Matrix to the list of external tools in SharpDevelop. This will allow you to launch Matrix without leaving the SharpDevelop IDE.

In SharpDevelop, go to Tools -> Options, click the Tools folder and select External Tools. Click "Add" and fill out the details as

Title ASP Web Matrix
Command <browse to WebMatrix.exe>
Arguments "${ItemPath}"
Working dir ${ItemDir}

Now add all your .aspx files to your SharpDevelop project. When you need Web Matrix, double-click your .aspx file in the Project browser, and select Tools -> ASP Web Matrix

Still not quite Visual Studio - but still about $2500 cheaper ;o)
# May 30, 2005 10:26 PM

MG said:

This is exactly what I have been looking for. Only problem is that I am not familiar with C coding and my vb OOP skills are still in early stages. If anyone can send me the above implementation for VB language it would be greatly appreciated.
I understand the steps are all the same so all I really need is the class in vb language.
Thanks!
gotts@bezeqint.net
# June 14, 2005 2:03 PM

David said:

Your C# with ASP.NET Web Matrix worked like a charm. It was just what I needed because when I ran other code that other people had written I kept getting the message "Assembly location different" or something to that effect. Also they said that References needed to be set in the C# compiler (referring to C#.NET)

For those of us that don't have the .NET IDE and wanted a simple solution with everything in one place (Sharpdevelop and ASP.NET Web Matrix), this was it.

Thank you,

David
# August 10, 2005 11:28 PM

Matt said:

Thanks, Mark!

I've worked with ASP for a number of years now, but I'm brand-spanking new to .net. The syntax is one thing (I'm using VB), but understanding the framework has been the real challenge. Codebehind, compiling, etc. were totally foreign to me until very recently.

I recently outsourced a .net project, and I've been hacking around for a couple days now trying to figure out how to get a simple modification to work. Every option I tried failed, until now. I imagine SharpDevelop is fairly intuitive to someone who's used VS, but I've never touched it. Your tutorial is just what I needed.

Thanks,

Matt
# August 17, 2005 12:15 PM

mamala said:

hi,

i tried this...but parse error occurs..

says that mycodebehindclass is not inherited from System.Web.UI.Page

I have done exactly the same way above...

I cannot understand the problem..
# September 26, 2005 3:22 AM

georgeduke said:

It's very great !!! I like Sharpdevelop, and it's so cool to develop in asp.net within !!!
# December 19, 2005 3:14 PM

chuthulu said:

but an error occurs
/ - Parse error

mycodebehindclass does not inherit system.web.ui.page

but i had done that...still error persists...

any help..
pls ...pls..
# April 14, 2006 8:26 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

Our Sponsors

Free Tech Publications

This Blog

Syndication

News