Assign a static port to Website

by Vahid 15. December 2009 08:04
A while ago in a project we had the requirement to assign a static port number to our website project. The very first thing came to my mind was that we just can assign static port number to web application project type and we cannot assign a static port to web site project. Anyway I started searching in the internet for a solution to make sure about it. I spent quit a long time looking for an answer but I could not find any almost everywhere it was mentioned that we cannot assign a static port to a website and it is constrained to use dynamic port.I was convinced at the time and we managed to convert to web application. Surprisingly recently a friend of mine, Ali, referred a perfect solution for this issue to me and I thought it’s worth sharing with you. Step 1- the very first step is to add the Web Server external tool to Visual Studio. To do so
  • go to the Tool menu
  • Click on the External Tool menu


Step 2- next step is to actually adding the external tool. Once the external tool window is open, click on Add button and
  • In the title text box give your web server a name (in this case I have called it webserver 1919).
  • In the command text box enter your .net web server address (in my computer it is C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE)
  • In the Arguments text box enter /port:{port number} /path:$(ProjectDir) where {port number} is your desired static port number (in this case I have chosen port 1919 and the value is “/port:1919 /path:$(ProjectDir)”).
  • Tick use output window check box
  • Click on the Ok button


Step 3- now that the external tool is added and ready to use you have to change your website project setting to use this web service rather than default web service. To do so
  • Right click on your project file and click on the Property Pages menu.
  • On the left side of the property window click on Start Options.
  • In the Server section choose Use custom server
  • In the base URL text box enter http://localhost:1919 where 1919 should be the port number you have chosen in step 2
  • Click on the Ok button


Step 4- the last step is to start the custom web server before debugging the application. To do so:
  • Click on the Tool menu. Now a new menu item having the name you have assigned to the customer web server in step 2 should be displayed in the tool menu.
  • Click on the new menu item (in this case webserver 1919)

Now you are ready to go. Click F5 and start debugging your web site on a static port.



Differences between web Site and Web Application

by Vahid 10. December 2009 06:05
Have ever wondered what the differences between 2 types of web projects in visual studio 2005 ( web site project and web application project) are?Well personally I had some idea here and there about the differences but when I found the following tables from MSDN which describe the differences in an organized way, I thought of sharing them with you.Just one important thing is missing and this is:In web application project we can assign a static port number for your internal web server whereas in web site project we are restricted to use the dynamically assigned port number. Static port number assignment functionality comes handy in many situation starting from an automated testing.The following table lists Web project options or tasks and indicates which project model best implements those options.

Option or Task

Web Application Projects Web Site Projects
Need to migrate large Visual Studio .NET 2003 applications X  
Prefer single-page code model to code-behind model   X
Prefer dynamic compilation and working on pages without building entire site on each page view (that is, save file and then simply refresh the page in the browser).   X
Need to control names of output assemblies X  
Need to generate one assembly for each page   X
Need stand-alone classes to reference page and user control classes X  
Need to build a Web application using multiple Web projects X  
Need to add pre-build and post-build steps during compilation X  
Want to open and edit any directory as a Web project without creating a project file   X
The following table helps you select a project type by describing some of the key differences between Web application projects and Web site projects.


Web Application Project Web Site Project
Project definition Similar to Visual Studio .NET 2003. Only files that are referenced in the project file are part of the project, are displayed in Solution Explorer, and are compiled during a build. Because there is a project file, some scenarios are more easily enabled: You can subdivide one ASP.NET application into multiple Visual Studio projects.You can easily exclude files from the project and from source code-control. Web site projects use the folder structure to define the contents of the project. There is no project file and all files in the folder are part of the project. This project type is desirable if you have an existing folder structure representing an ASP.NET application that you want to edit in Visual Studio without having to explicitly create a project file.
Compilation and build outputs The compilation model for Web application projects is very similar to that in Visual Studio .NET 2003. All code-behind class files and stand-alone class files in the project are compiled into a single assembly, which is placed in the Bin folder. Because this is a single assembly, you can specify attributes such as assembly name and version, as well as the location of the output assembly.Certain other applications scenarios are better enabled, such as the Model-View-Controller (MVC) pattern, because they allow stand-alone classes in the project to reference page and user control classes. The Build command compiles Web site projects only to test them. To run Web site projects, you deploy source files and rely on ASP.NET dynamic compilation to compile pages and classes in the application. Alternatively, you can precompile the site for performance, which uses the same compilation semantics as ASP.NET dynamic compilation. The ASP.NET dynamic compilation system has two modes—batch mode (the default) and fixed-names mode. In batch mode, many assemblies (typically one per folder) are produced when precompiling the site. In fixed mode, one assembly is produced for each page or user control in the Web site.
Iterative development To run and debug pages, you must build the entire Web project. Building the entire Web application project is usually fast, because Visual Studio employs an incremental build model that builds only the files that have changed. You can configure build options Visual Studio 2005 for when you run the site: build the site, an individual page, or nothing at all. In the last case, when you run a Web site, Visual Studio simply launches the browser and passes to it the current or start page. The request then invokes ASP.NET dynamic compilation. Because pages are compiled dynamically and compiled into different assemblies as needed, it is not required that the entire project compile successfully in order to run and debug a page.By default, Visual Studio completely compiles Web site projects whenever you run or debug any page. This is done to identify compile-time errors anywhere in the site. However, a complete site build can significantly slow down the iterative development process, so it is generally recommended that you change the build project option to compile only the current page on run or debug.
Deployment Because all class files are compiled into a single assembly, only that assembly needs to be deployed, along with the .aspx and .ascx files and other static content files. In this model, .aspx files are not compiled until they are run in the browser. However, when used with Web Deployment Projects (a downloadable add-in to Visual Studio 2005), the .aspx files can also be compiled and included in a single assembly for deployment.Each time you deploy the single assembly produced in this model, you replace the code for all pages in the project. Both .aspx files and code-behind files can be compiled into assemblies using the Publish Website command in Visual Studio. (Note that the Build command does not create a deployable set of assemblies.) The updateable publish option supports compiling only code-behind files while leaving .aspx files unchanged for deployment. The default mode for precompiling produces several assemblies in the Bin folder, typically one per folder. The fixed-names option produces one assembly per page or user control and can be used to create deployable versions of individual pages. However, the fixed-names option increases the number of assemblies and can result in increased memory usage.
Upgrade from Visual Studio .NET 2003 Because the Web application project model is the same as in the Visual Studio .NET 2003, upgrade is generally simple and will usually not require any restructuring of the application. The compilation option for Web site projects is significantly different than Visual Studio .NET 2003. A conversion wizard is available to upgrade existing Visual Studio .NET 2003 Web projects to Web site projects. For any reasonably complex Visual Studio .NET 2003 projects, manual fix-up is usually required after the conversion. For most scenarios, it is preferable to upgrade existing Visual Studio .NET 2003 projects to Web application projects in Visual Studio 2005.

Tags: ,

.Net | Learning resource | Technical

Export to PDF, Excel and Image in

by Vahid 18. July 2009 19:48

recently in our project we had a requirement to export html to PDF in there are so many components around which we can use to do this but the restriction for us was that we had to do it without spending money means we had to go for an open source component. doing so much I&D on this, we came to know about itextSharp which is a powerful open source component to create PDF files in .net. first it seemed good to us but spending sometimes on it we came to know it was not what we were looking for. two reason for that:

  1. it requires a big learning curve
  2. it’s not at all easy to work with

then the idea of using crystal report came to our mind. we could build the report in crystal report, load it through code without showing anything to user and through it’s API calling the export to pdf function. but it did not work since we had to run some setup components on the live server which we are not allowed to do.

meantime i just remembered we have rdlc reports in .net framework and also Microsoft report viewer. since these are .net component we don't have to install anything on the production server and Xcopy of the required assemblies will work for us. normally you can deploy the .net report files (.rdlc) using xcopy but in order to be able to use the reports you need to install Microsoft report viewer redistributable package which is freely available to download and distribute. this is fine when you have the rights to install components on the server. anyways spending sometime on this technology i found the files required to make the functionality up and running. if you don't want to install report viewer component you need to put these four dll in your bin folder:


you can download the files from here:

you need to create a report file by click on add new item in your project and selecting Report. then you need to design your report in visual studio as desired. you can use report parameters as placeholder for the values to be passed to to report.

then you need the following lines of code to export:

string[] streamids;
string mimeType;
string encoding;
string extension;
string fileFormat = "PDF";//can also be "Excel" or "Image";
Microsoft.Reporting.WebForms.LocalReport localReport = 
new Microsoft.Reporting.WebForms.LocalReport();
localReport.ReportPath = Server.MapPath("Report1.rdlc");
Microsoft.Reporting.WebForms.Warning[] warnings;
byte[] bytes = localReport.Render(
fileFormat, null, out mimeType, out encoding,
out extension,
out streamids, out warnings);
System.IO.FileStream fs = 
new System.IO.FileStream(Server.MapPath("output.pdf"),
fs.Write(bytes, 0, bytes.Length);

remember you can export to PDF, Excel and Image

you can use this method both for applications and windows application.

hope this comes handy for you.

Tags: , ,

.Net | Technical

Managing Multiple Configuration File For Different Application Life cycles In .Net Applications

by Vahid 25. May 2009 16:50

All of us have already dealt with the problem of promoting configuration files in different application life cycles. this problem can be as simple as managing different connection strings for different databases in each environment to managing the other complicated settings in each environment.

so many times it happens that we forget to update the configuration file (web.config or app.config) before promotes. what we had already done was to keep one configuration file for each environment (development, testing, staging …) and after promote before build overwrite the the existing configuration file. but even in this case we used to miss to update the configuration file with the latest information. anyway i came across the very good solution in Scott Hanselman's blog. ok here is the solution.

  1. In your project Click the configuration management dropdown and select "Configuration Manager."image

You'll probably have Debug and Release configurations, but you can also make custom ones and base them on existing configuration. In this dialog I've made a new "Deploy" and I'll base it on the "Release" configuration.

WindowClipping (8)

Make sure to create a Solution Configuration AND a Project Configuration, as they are different. Here I've made one called Deploy for the Project also. If you get an error message, be aware of the "Create new project configurations" checkbox. You might get a warning if you are making a new configuration and the dialog tries to make another configuration with the same name; uncheck the checkbox if that happens. Of course, you can have as many Configurations as you'd like.


2. Add some custom configuration stuff in web.config, like connectionStrings:

	   1: <connectionStrings>
	   2:     <add name="Foo"
	   3:          connectionString="Data Source=localhost;Initial Catalog=DatabaseName;
	   4:                            User Id=sa;Password=debug;"
	   5:          providerName="System.Data.SqlClient" />
	   6: </connectionStrings>

See now I've made the password in my nonsense connectionString = "debug"? Now, create three new web.config's by CTRL-dragging the web.config on top of the project. Name them web.config.debug, web.config.deploy, and web.config.release. Make the password equal to "deploy" and "release" respectively.

WindowClipping (10)

3. Ok,  now we've got different configuration and different configuration files. Let's create a batch file called "copyifnewer.bat" and here's the contents:

	   1: @echo off
	   2: echo Comparing two files: %1 with %2
	   4: if not exist %1 goto File1NotFound
	   5: if not exist %2 goto File2NotFound
	   7: fc %1 %2 
	   8: if %ERRORLEVEL%==0 GOTO NoCopy
	  10: echo Files are not the same.  Copying %1 over %2
	  11: copy %1 %2 /y & goto END
	  13: :NoCopy
	  14: echo Files are the same.  Did nothing
	  15: goto END
	  17: :File1NotFound
	  18: echo %1 not found.
	  19: goto END
	  21: :File2NotFound
	  22: copy %1 %2 /y
	  23: goto END
	  25: :END
	  26: echo Done.

Basically this batch file will copy a file over another if the files don't match. It's not strictly "copyifnewer" (like, not at all) but it does the job.

Why bother with a batch file to check for changes and not just copy over the file every time? Well, each time you copy over a web.config it restarts all the designers and running AppDomains that are watching that file. No need to copy over a file if it hasn't changed...everything will churn less.

Put this copyifnewer.bat file in the root of your project.

WindowClipping (10)

4. Create a Pre-build Event. Right-click on your Project and select Properties. Click Build Events and in the "Pre-build event command line" and enter this value:

	"$(ProjectDir)copyifnewer.bat" "$(ProjectDir)web.config.$(ConfigurationName)" "$(ProjectDir)web.config"

Notice the magic dust, the $(ConfigurationName) project variable, that contains "Debug" or "Release" or "Deploy."

WindowClipping (9)

5. Build. Now if you build, you'll see in the Build Output the batch file being run and the files being copied. Because it's a Pre-Build Event it'll be seen in both the Build Output in Visual Studio .NET.

When you build within Visual Studio the currently selected item in the drop-down list is the current configuration.  now you have different configuration file for each build

there is catch here and that is we have to remember that we've got to keep web.config's in sync if there's lots of settings, but we could totally break it apart via "include files."

Tags: , ,

.Net | Technical

Optimizing Silverlight pages to be search engine friendly

by Vahid 31. March 2009 14:49

recently i was involved in development of an web application whose interface was based on Microsoft Silverlight. as Silverlight is a new technology we had so much challenges to get the job done but out of them the most important one for us was to make the application search engine friendly. so after doing some I&D on it and spending some late night hours on the issue, i got some good references and experiences which i thought of sharing them with you.

This document describes some best practices for search engine optimization of Silverlight applications. These practices are designed to help developers make their Silverlight content discoverable on a search engine results page and to provide an acceptable experience for users who do not have Silverlight enabled.

This document contains the following sections:


As we all know The goal of search engine optimization (SEO) is to increase the chances that your page will appear in the main section of the search engine results page (outlined by the red rectangle in Figure 1), not the paid or sponsored results.

Search engine results page.

Figure 1 - Search engine results page

Even though the search landscape is rapidly changing, with multiple competitors continuously improving and evolving how they implement search, SEO relies on some fundamental similarities among search engine algorithms.

Lets Take A Look At How Search Engines Work

Search engines crawl, weight, and index Web page content. Crawling is done by a search robot that traverses the links in a Web site and captures the content. Search engines then use algorithms and heuristics to assign weights to Web pages. This information is used to build the search index, which is used to build a results page based on your query.

The main reason for a Web page to be highly ranked in search engine results is that the words on the page match the keywords that are used to search. The presence of dynamic and nonstandard elements such as script, style, object, and embed tags in the page is a challenge to search engines, and this is an area where they have traditionally not done well.

In this situation, search engines have to do the following:

  • Download linked content and associate it with the source page.
  • Parse, convert, execute, or render elements to obtain the same experience as the user viewing the page in a browser.

Figure 2 is a simplified view of how a search engine works.

A simplified view of the search engine.

Figure 2 - A simplified view of a search engine

Approaches for Developing a Silverlight Application

If you are planning to build a Silverlight application, there are things you can do to make sure that your application is discovered and returned by search engines.

The following are some of the patterns that you can adopt for how your application coexists with the HTML content.

We Should Mix HTML with Silverlight Content

This pattern involves mixing HTML text with Silverlight content in the same page so that it delivers richness in functionality and the native HTML content is consumable by search engines. To do this, consider designing your Silverlight content in such a way that it fits within, or around, a block of text. This looks like a grid of interacting components that fit around HTML text. An advantage of this approach is that it ensures that your Silverlight interactivity is truly supporting the text, rather than hiding otherwise searchable text from search engines. Figure 3 shows a Web page with this approach.

Islands of text and Silverlight interactivity

Figure 3 - Islands of text and Silverlight interactivity

Use HTML Bridge to Generate Silverlight Content Dynamically

This approach is slightly harder to achieve and can be limiting to the Silverlight experience. You will have most success with this approach if you have existing XHTML content and want to enhance the experience with Silverlight. In this approach, the XHTML content is the base experience for search robots and down-level clients, while the Silverlight experience is reserved for consumers on client platforms capable of running Silverlight.

In this approach, the XHTML content has the full-fidelity experience for its target clients. It is still declared as nested alternate content within the object tag for the Silverlight plug-in. The one attribute that differentiates this pattern from the graceful degradation pattern is that in this pattern, the Silverlight application’s UI is driven by the nested alternate content. In other words, application logic will use the DOM Bridge to get the nested alternate content from the object tag and use it to construct the Silverlight UI. This can be as simple as using XSLT to transform the XHTML to XAML, or perhaps using data binding to bind XAML UI properties to an object representing content from the extracted markup.

Graceful Degradation

In this document, we focus primarily on search engine optimization using the graceful degradation approach. In such a scenario, the Silverlight content is the primary experience for consumers, and the use of nested alternate content within the object tag serves as the down-level experience.

Search Engine Optimization Techniques for Silverlight Applications

The key consideration for making Silverlight content indexable by search engines is to use the approaches that are used for systems and users for which Silverlight is not enabled. Considerations include the following:

  • How the Web page with Silverlight content behaves in client/browser configurations such as Opera or Windows 98, which are not currently supported by Silverlight.
  • How the Web page behaves for customers who use accessibility programs such as screen readers and narrators.
  • How the Web page behaves for customers who use from a text browser such as Lynx, where no scripts can execute.

Presenting contextual metadata and alternate content that would make Silverlight content friendly to down-level users will also make it friendly to search engines.

When creating your Silverlight application, do not assume that all users will have Silverlight installed or have computers with the ability to install Silverlight. Prepare for how you would describe your application to these users.

  • Know your audience.
  • Plan on how you would describe your application to them.
  • Identify the keywords that you would use to connect with searchers.

The words that you use in your titles, page and section headers, body content, and alternate content play an important role in how the search engines find and index your content, and also how a user finds your content.

The following are some of the techniques you can use to optimize your search engine results and improve the experience for all users:

Use a Descriptive Page Title

Give your page a good title. Web page authors must update and customize the markup in the pages generated by Silverlight project templates in Visual Studio or Expression Blend. For the purposes of discussion, let’s assume you have a Silverlight application that provides interactive traffic maps for the Seattle area. Figure 4 shows bad (default) and good Web page titles.

Bad and good page titles

Figure 4 - Bad and good page titles

Add Description Metadata

Keywords in your page’s meta tag are not very useful for search engines to determine your page’s rank. However, a page title and meta description tag (that is, a meta tag whose name attribute is set to "description") are extremely useful in ensuring that searchers who view your page on a results page associate it with content that they are looking for.

If you have a top-level Silverlight application that occupies the full extent of the browser’s client area, or one that exists on your landing page, then you must have a meta description tag on your HTML page. The following code shows the format of the meta description tag.

<head> <meta name="description" content="Microsoft portal site for the Silverlight development community..." > ... </head>

If you have a page with a lot of text content that contains relevant keywords, then you can omit the meta description. The search engine will show a portion of your page content on the results page, and any stub description may actually prove counterproductive.

The following figure shows a sample search page entry with a description, and how it would appear if the meta description tag were not present.

Search results page with and without a meta description tag

Figure 5 - Search results page with and without a meta description tag

Use a Meaningful Application Name

Giving a useful name to your application is another way to help the search engines find your Web page. For example, an application that provides traffic maps for the Seattle area could be named SeattleTrafficMaps.xap.

Even if your application was built using a different name, it is easy to change the name, for example, from MyTestSLApp.xap to SeattleTrafficMaps.xap. Changing the name back at a later time is a simple operation if that name is not referred to elsewhere in your code. By default, there are no dependencies of this kind in the Silverlight templates.

Use the object Tag

The object tag in HTML is designed so that if the main object cannot be loaded to display content, then browser clients will continue to look for alternative content within the object tag.

Silverlight content publishers must use the object tag (not the embed tag) to instantiate Silverlight. The following code shows how you can add the object tag.

<object type="application/x-silverlight-2" data="data:application/x-silverlight," width="..." height="..."> <param name="source" value="SeattleTrafficMaps.xap" /> <!-- Other parameters, if any --> ... <!-- The “Get Silverlight” messages and badge --> <p>This content requires Microsoft Silverlight. <a href="" style="text-decoration: none;"> <img src="" alt="Get Microsoft Silverlight" style="border-style: none"/> </a> </p> </object>

Specify Alternate Content for Silverlight

The object tag for the Silverlight application must be supplemented with nested alternate content, namely the inner HTML that is displayed on systems where Silverlight is absent. The following code shows how you can do that.

<object type="application/x-silverlight-2" data="data:application/x-silverlight," width="..." height="..."> <param name="source" value="SeattleTrafficMaps.xap" /> <!-- Other parameters, if any --> ... <!-- Nested alternate HTML content for search --> <h3>Traffic map of the Seattle-Puget Sound area</h3> <p>Up-to-the-minute traffic situation overlaid on the map of the Seattle-Puget Sound area, powered by <a href="">Live Maps</a> </p> <!-- Canned image representing the application contents --> <img src="SeattleTraffic_RushHour.jpg" alt="Seattle traffic at 5:30pm (evening rush-hour)" /> <!-- The “Get Silverlight” message and badge --> <p>This content requires Microsoft Silverlight. <a href="" style="text-decoration: none;"> <img src="" alt="Get Microsoft Silverlight" style="border-style: none"/> </a> </p> </object>

Use createObject When Using Silverlight.js

The primary function of Silverlight.js is to provide a cross-browser, cross-platform means of constructing the right markup to get Silverlight content hooked up to the HTML DOM. Typically this involves working around browser quirks to generate the object tag with the right set of parameters. The createObject function also takes the id of a parent element, for example a div or span, within which the Silverlight object will be hooked up as child element. This approach uses the following logic.

if (slParentElement != null) { slParentElement.innerHTML = slPluginHTML; }

For example, assume that your markup consisted of the following code.

<div id="divWithinWhichSLObjectExists"> <script type="text/javascript"> Silverlight.createObject("slObjectId", "divWithinWhichSLObjectExists", ...); </script> </div>

The effective DOM would be like the following code when executed on the browser.

<div id="divWithinWhichSLObjectExists"> <object type="application/x-silverlight-2" data="data:application/x-silverlight," width="..." height="..."> <param name="source" value="SeattleTrafficMaps.xap" /> <!-- Other Parameters, if any --> ... <!-- The “Get Silverlight” message and badge --> <p>This content requires Microsoft Silverlight. <a href="" style="text-decoration: none;"> <img src="" alt="Get Microsoft Silverlight" style="border-style: none"/> </a> </p> </object> </div>

This has a beneficial side effect for the following reasons:

  • Replacing the inner HTML of the parent div removes any other existing child elements in that div.
  • Search engines often parse and index markup as it is served—before any scripts execute and change the DOM.

In other words, you can add detailed contextual metadata as native HTML within the parent div element of the Silverlight object. Search engines will process the metadata, but the metadata will not show up in the browser.

If your parent div has nested contextual content, the following code is what the search robot sees.

<div id="divWithinWhichSLObjectExists"> <!-- Nested alternate HTML content for search --> <div> <h3>Traffic map of the Seattle-Puget Sound area</h3> <p>Up-to-the-minute traffic situation overlaid on the map of the Seattle-Puget Sound area, powered by <a href="">Live Maps</a> </p> <!-- canned image representing app contents --> <img src="SeattleTraffic_RushHour.jpg" alt="Seattle traffic at 5:30pm (evening rush-hour)" /> </div> <!-- Invocation of the createObject function in Silverlight.js --> <script type="text/javascript"> Silverlight.createObject("slObjectId", //SL plug-in id "divWithinWhichSLObjectExists", //parent id ...); </script> </div>

Test Down-Level Experiences

Regardless of the relative importance of Silverlight and HTML in your content, it is important to test the page as a user who does not have Silverlight installed.

To access the page as a down-level user, perform the following steps:

  1. Close all instances of Internet Explorer, and then start a new instance.
  2. On the Tools menu, point to Manage Add-ons, and then click Enable or Disable Add-ons. The Manage Add-ons dialog box is displayed.
  3. Select Microsoft Silverlight, select the Disable button, and then click OK.
  4. Restart Internet Explorer and navigate to the Web page that has your Silverlight content.

To revert, return to the Manage Add-ons dialog box, select Microsoft Silverlight, and select Enable.


The procedure for temporarily disabling the Silverlight plug-in differs depending on the browser you are using.

After you have tested the down-level experience, it is worthwhile validating your page with a static analysis tool such as SEO Browser that understands the impact of markup and content on search engine optimization.


The ability of search engines to index content that is not native HTML is very limited. However, if you structure and present your Silverlight application in certain ways, they have a better chance of appearing on a search engine results page in response to a search query.

Tags: , ,

.Net | Learning resource | Technical

Free ASP.NET MVC eBook Tutorial from Scott Guthrie

by Vahid 18. March 2009 06:43

Scott Guthrie, Scott Hanselman, Rob Conery, and Phil Haack have release a book named ASP.NET MVC 1.0. first chapter of the book which is writen by Scott Guthrie is available to download for free. if you are new to MVC and also eager to know more about LINQ to SQL then you need to check this out. as always scott discribes the topics in practical manner so that we learn it much better. any way the chapter is available at the following link. download it, go through it and dont forget to thank scott.

  • Download the free end-to-end tutorial chapter in PDF form
  • Download the source code + unit tests for the completed application

    Tags: , ,

    .Net | Learning resource | Technical

    ASP.NET Web User Controls VS. Web Custom Controls

    by Vahid 3. March 2009 03:54

    Web user controls are easy to make, but they can be less convenient to use in advanced scenarios. You develop Web user controls almost exactly the same way that you develop Web Forms pages. Like Web Forms, user controls can be created in the visual designer, they can be written with code separated from the HTML, and they can handle execution events. However, because Web user controls are compiled dynamically at run time they cannot be added to the Toolbox, and they are represented by a simple placeholder glyph when added to a page. This makes Web user controls harder to use if you are accustomed to full Visual Studio .NET design-time support, including the Properties window and Design view previews. Also, the only way to share the user control between applications is to put a separate copy in each application, which takes more maintenance if you make changes to the control.

    Web custom controls are compiled code, which makes them easier to use but more difficult to create; Web custom controls must be authored in code. Once you have created the control, however, you can add it to the Toolbox and display it in a visual designer with full Properties window support and all the other design-time features of ASP.NET server controls. In addition, you can install a single copy of the Web custom control in the global assembly cache and share it between applications, which makes maintenance easier.

    considering the kind of flexibility we get from web custom controls, i believe most of the times it would be much better to use custom controls.

    Web user controlsWeb custom controls
    Easier to create Harder to create
    Limited support for consumers who use a visual design tool Full visual design tool support for consumers
    A separate copy of the control is required in each application Only a single copy of the control is required, in the global assembly cache
    Cannot be added to the Toolbox in Visual Studio Can be added to the Toolbox in Visual Studio
    Good for static layout Good for dynamic layout


    .Net | Technical

    Integrating PayPal Payments into E-Commerce Applications with ASP.NET

    by Vahid 1. March 2009 16:24

     Check out the following article about Integrating PayPal Payments into ASP.NET E-Commerce Applications. this a very descriptive, useful article.

    The process of integrating a PayPal payment involves several pages and HTTP POST backs.

    Tags: , ,

    .Net | Learning resource | Technical

    export to excel but in new page

    by Vahid 20. January 2009 05:42

    in the last sub system which we were working on, there was requirement to export the result of a query which is from oracle database and is displayed in an data grid into excel file. but the component we are using for export to excel functionality gets the collection as input parameter and export the data to excel file and write the excel file into response object of the this means once the functionality is invoked, a dialog box will be displayed asking Open the file, save the file of cancel the operation. no issue with save and cancel. but when they clicked on the open it opens the excel file in the same browser window where they were viewing the page and they close the window once they were through with viewing the excel file. this means they close the application.

    now they needed the excel file be opened in a new window so that they will not loos their application states. what we did to do so is a little bit tricky. in the query page when user clicks on export to excel button we save the data to be exported in an session state and open a new browser on the user's machine using following code :

    BaseList<QueryInvoiceResult> result = GetInvoices(p);

    Session["exceldata"] = result;


    and we also moved the export to excel logic to the ExcelExport.aspx page



    if (Session["exceldata"] != null)


    BaseList<QueryInvoiceResult> result = (BaseList<QueryInvoiceResult>)Session["exceldata"];if (result.Count > 0)






    catch (Exception)






    "exceldata"] = null;




    .Net | Technical