ASP.NET PHP.NET CODEITWELL MASHABLE OPENSOURCEWEBDESIGN BLOGDUMPS FACEBOOK APPS

Home ASP.NET PHP WINDOW Web Programming Web Logic Web Design css Archives
Sunday, August 30

RadioButtonList DropDownList In GridView Edit Mode In ASP.NET

0 comments

In this example i am going to describe how to implement RadioButtonList and DropDOwnList in Edit mode of GridVIew using EditItemTemaplate in ASP.NET C# and VB.NET.


RadioButton and DropDOwnList are selected in edit mode based on value saved in DataBase



HTML markup of aspx page is mentioned below
<span class="kwrd"><</span><span class="html">asp:GridView</span> <span class="attr">ID</span>
<span class="kwrd">="GridView1"</span> <span class="attr">runat</span><span class="kwrd">="server"
</span> <span class="attr">DataKeyNames</span><span class="kwrd">="ID"</span>
<span class="attr">AutoGenerateColumns</span><span class="kwrd">="False"</span>
<span class="attr">DataSourceID</span><span class="kwrd">="SqlDataSource1"</span>
<span class="attr">OnRowDataBound</span><span class="kwrd">=
"GridView1_RowDataBound"</span>
<span class="attr">OnRowUpdated</span><span class="kwrd">="GridView1_RowUpdated"</span>
<span class="attr">OnRowUpdating</span><span class="kwrd">="GridView1_RowUpdating"</span>
<span class="attr">OnRowEditing</span><span class="kwrd">="GridView1_RowEditing"</span>
<span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">Columns</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:TemplateField</span> <
span class="attr">HeaderText</span>
<span class="kwrd">="ID"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">ItemTemplate</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:Label</span> <span
class="attr">ID</span><span class="kwrd">="lblID"</span>
<span class="attr">runat</span><span class="kwrd">="server"</span> <span class="attr">Text</span>
<span class="kwrd">='<%#Eval("ID") %>'</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">asp:Label</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">ItemTemplate</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">asp:TemplateField</span><span class="kwrd">></span>

<span class="kwrd"><</span><span class="html">asp:BoundField</span> <span class="attr">DataField</span>
<span class="kwrd">="Name"</span>
<span class="attr">HeaderText</span><span class="kwrd">="Name"</span>
<span class="attr">SortExpression</span><span class="kwrd">="Name"<
/span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">asp:TemplateField</span> <
span class="attr">HeaderText</span>
<span class="kwrd">="Gender"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">ItemTemplate</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:Label</span> <span
class="attr">ID</span><span class="kwrd">="lblGender"</span>
<span class="attr">runat</span><span class="kwrd">="server"</span>
<span class="attr">Text</span><span class="kwrd">='<%#Eval("Sex") %>'</span>
<span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">asp:Label</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">ItemTemplate</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">EditItemTemplate</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:RadioButtonList</span>
<span class="attr">ID</span>
<span class="kwrd">="rbGenderEdit"</span>
<span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:ListItem</span><span class="kwrd">></span>Male
<span class="kwrd"></</span><span class="html">asp:ListItem</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:ListItem</span><span class="kwrd">></span>
Female<span class="kwrd"></</span><span class="html">
asp:ListItem</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">asp:RadioButtonList</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">EditItemTemplate</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">asp:TemplateField</span><span class="kwrd">></span>

<span class="kwrd"><</span><span class="html">asp:TemplateField</span>
<span class="attr">HeaderText</span><span class="kwrd">="Marital Status"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">ItemTemplate</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:Label</span> <span class="attr">ID</span>
<span class="kwrd">="lblStatus"</span> <span class="attr">runat</span><span class="kwrd">="server"</span>
<span class="attr">Text</span><span class="kwrd">='<%#Eval("MaritalStatus") %>'</span>
<span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">asp:Label</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">ItemTemplate</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">EditItemTemplate</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:DropDownList</span> <span class="attr">ID</span>
<span class="kwrd">="ddlStatusEdit"</span> <span class="attr">runat</span><span class="kwrd">="server"</span>
<span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:ListItem</span><span class="kwrd">><
/span>Single<span class="kwrd"></</span>
<span class="html">asp:ListItem</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:ListItem</span><span class="kwrd">></span>
Married<span class="kwrd"></</span>
<span class="html">asp:ListItem</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">asp:DropDownList</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">EditItemTemplate</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">asp:TemplateField</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:CommandField</span> <span class="attr">
ShowEditButton</span><span class="kwrd">="True"</span> <span class="kwrd">/></span>
<span class="kwrd"></</span><span class="html">Columns</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">asp:GridView</span><span class="kwrd">></span>

<span class="kwrd"><</span><span class="html">asp:SqlDataSource</span> <span class="attr">ID</span>
<span class="kwrd">="SqlDataSource1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span>
<span class="attr">ConnectionString</span><span class="kwrd">="<%$ ConnectionStrings:ConnectionString %>"</span>
<span class="attr">SelectCommand</span><span class="kwrd">="SELECT [ID], [Name], [Sex], [MaritalStatus]
FROM [Details]"</span>
<span class="attr">UpdateCommand</span><span class="kwrd">="Update Details Set [Name]=@Name, [Sex]=@Sex,
[MaritalStatus]=@MaritalStauts Where [ID]=@ID"</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">UpdateParameters</span><span class="kwrd">></span>
<span class="kwrd"><</span><span class="html">asp:Parameter</span> <span class="attr">Name</span>
<span class="kwrd">="Name"</span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">asp:Parameter</span> <span class="attr">Name</span>
<span class="kwrd">="Sex"</span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">asp:Parameter</span> <span class="attr">Name</span>
<span class="kwrd">="ID"</span> <span class="kwrd">/></span>
<span class="kwrd"><</span><span class="html">asp:Parameter</span> <span class="attr">Name</span>
<span class="kwrd">="MaritalStauts"</span> <span class="kwrd">/></span>
<span class="kwrd"></</span><span class="html">UpdateParameters</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">asp:SqlDataSource</span><span class="kwrd">></span>
C# Code Behind
01.protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
02.{
03. DataRowView dRowView = (DataRowView)e.Row.DataItem;
04. if (e.Row.RowType == DataControlRowType.DataRow)
05. {
06. if ((e.Row.RowState & DataControlRowState.Edit) > 0)
07. {
08. RadioButtonList rblGender = (RadioButtonList)e.Row.FindControl("rbGenderEdit");
09. DropDownList ddlStatus = (DropDownList)e.Row.FindControl("ddlStatusEdit");
10. rblGender.SelectedValue = dRowView[2].ToString();
11. ddlStatus.SelectedValue = dRowView[3].ToString();
12. }
13. }
14.
15.}
16.
17.protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
18.{
19. RadioButtonList rblGender = (RadioButtonList)GridView1.Rows[e.RowIndex].FindControl("rbGenderEdit");
20. DropDownList ddlStatus = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlStatusEdit");
21. SqlDataSource1.UpdateParameters["Sex"].DefaultValue = rblGender.SelectedValue;
22. SqlDataSource1.UpdateParameters["MaritalStauts"].DefaultValue = ddlStatus.SelectedValue;
23.}
VB.NET Code Behind
01.Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
02. Dim dRowView As DataRowView = DirectCast(e.Row.DataItem, DataRowView)
03. If e.Row.RowType = DataControlRowType.DataRow Then
04. If (e.Row.RowState And DataControlRowState.Edit) > 0 Then
05. Dim rblGender As RadioButtonList = DirectCast(e.Row.FindControl("rbGenderEdit"), RadioButtonList)
06. Dim ddlStatus As DropDownList = DirectCast(e.Row.FindControl("ddlStatusEdit"), DropDownList)
07. rblGender.SelectedValue = dRowView(2).ToString()
08. ddlStatus.SelectedValue = dRowView(3).ToString()
09. End If
10.
11. End If
12.End Sub
13.
14.Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
15. Dim rblGender As RadioButtonList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("rbGenderEdit"), RadioButtonList)
16. Dim ddlStatus As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("ddlStatusEdit"), DropDownList)
17. SqlDataSource1.UpdateParameters("Sex").DefaultValue = rblGender.SelectedValue
18. SqlDataSource1.UpdateParameters("MaritalStauts").DefaultValue = ddlStatus.SelectedValue
19.End Sub

Hope this helps.

Download sample code attached


Tutorial Videos. Hope this will greatly help you in ASP.NET videos

0 comments

Visual Web Developer Express

0 comments

Install Now with the Microsoft Web Platform Installer
Or Download Visual Web Developer

Visual Web Developer Express is a free Visual Studio Web development environment for building and testing next generation standards-based Web applications and services.


Visual Web Developer Express offers

  • A rich editor that allows you to work with HTML and CSS in source view, design view or both using split-view
  • Powerful debugging support for ASP.NET, C#, VB as well as JavaScript
  • Support for application frameworks like ASP.NET MVC, AJAX, Silverlight and third party libraries like jQuery
  • Built-in support for FTP-based Web deployment and database deployment
  • Intellisense features such as syntax highlighting and auto-completion that help improve productivity
  • Ability to test your Web applications instantly with the integrated Web server or IIS


IButtonControl in ASP.NET. Do you know this? Just try and see.

0 comments

One nice feature of ASP.NET 2.0 is a new interface called IButtonControl.
You can use it in a code behind to say a control needs to be a button
but without actually saying whether it needs to be a Button,
LinkButton, ImageButton or custom control button type.


This is the type of thing that’s useful if you have a code behind
used by multiple different aspx pages, each with slightly different
requirements of what the button should look like. It also means you can
switch between the three without having to change the code behind.


So instead of a huge ugly if statement like this:


Button button = Page.FindControl("Button1") as Button;
ImageButton imageButton = Page.FindControl("ImageButton1") as ImageButton;
LinkButton linkButton = Page.FindControl("LinkButton1") as LinkButton;
if(button != null)
button.Text = "Click me";
else if(imageButton != null)
imageButton.Text = "Click me";
else if(linkButton != null)
linkButton.Text = "Click me";

Instead you can support all three scenarios nice and simply like this:


IButtonControl button = Page.FindControl("Button1") as IButtonControl;<br />button.Text = "Click me";<br />

Retrieve value of Dynamic controls in asp.net; Most important part for beginners programming

0 comments

Object: our object is to access value of dynamic controls which are generated conditionally. For this, we will save viewstate of dynamic controls.
Suppose we have one dropdown and one button. When user selects “Generate” option, the Dynamic table will be generated. In each cell of table there will be textbox. User enters value in the textboxes and click on button then it will display all user entered values.

In aspx page

  1. <form id="form1" runat="server">  
  2.     <div>  
  3.         <asp:Table ID="tbl" runat="server">  
  4.         </asp:Table>  
  5.     <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"   
  6.         onselectedindexchanged="DropDownList1_SelectedIndexChanged">  
  7.         <asp:ListItem>Select...</asp:ListItem>  
  8.         <asp:ListItem>Generate</asp:ListItem>  
  9.     </asp:DropDownList>  
  10.         <asp:Button ID="btnSet" runat="server" Text="Button" onclick="btnSet_Click" /> </div>  
  11.     </form>  


To create dynamic control:
  1. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)  
  2.     {  
  3.         if (DropDownList1.SelectedIndex == 1)  
  4.         {  
  5.             CreateDynamicTable();  
  6.         }  
  7.     }  
  8. private void CreateDynamicTable()  
  9.     {  
  10.          
  11.         // Fetch the number of Rows and Columns for the table   
  12.         // using the properties  
  13.         int tblRows = 5;  
  14.         int tblCols = 5;  
  15.         // Now iterate through the table and add your controls   
  16.         for (int i = 0; i < tblRows; i++)  
  17.         {  
  18.             TableRow tr = new TableRow();  
  19.             for (int j = 0; j < tblCols; j++)  
  20.             {  
  21.                 TableCell tc = new TableCell();  
  22.                 TextBox txtBox = new TextBox();  
  23.                 txtBox.ID = "txt-" + i.ToString() + "-" + j.ToString();    
  24.                 txtBox.Text = "RowNo:" + i + " " + "ColumnNo:" + " " + j;  
  25.                 // Add the control to the TableCell  
  26.                 tc.Controls.Add(txtBox);  
  27.                 // Add the TableCell to the TableRow  
  28.                 tr.Cells.Add(tc);  
  29.                  
  30.             }  
  31.             // Add the TableRow to the Table  
  32.             tbl.Rows.Add(tr);  
  33.             tbl.EnableViewState = true;  
  34.             ViewState["tbl"] = true;  
  35.         }        
  36.     }  


On Button click
  1. protected void btnSet_Click(object sender, EventArgs e)  
  2.     {  
  3.         foreach (TableRow tr in tbl.Controls )  
  4.         {  
  5.             foreach (TableCell tc in tr.Controls)  
  6.             {  
  7.   
  8.                 if (tc.Controls[0] is TextBox)  
  9.                 {   
  10.                     Response.Write(((TextBox)tc.Controls[0]).Text);           
  11.                 }  
  12.             }  
  13.             Response.Write("  
  14. ");    
  15.         }  
  16.                 
  17.     }  


This time No output because dynamic controls are lost in postback then what to do.
So we need to save dynamic controls value and generate dynamic controls again.we need to maintain viewstate.
  1. protected override object SaveViewState()  
  2.     {  
  3.         object[] newViewState = new object[2];  
  4.   
  5.         List txtValues = new List();  
  6.                   
  7.         foreach (TableRow row in tbl.Controls)  
  8.         {  
  9.             foreach (TableCell cell in row.Controls)  
  10.             {  
  11.                 if (cell.Controls[0] is TextBox)  
  12.                 {  
  13.                     txtValues.Add(((TextBox)cell.Controls[0]).Text);  
  14.                 }  
  15.             }  
  16.         }  
  17.   
  18.         newViewState[0] = txtValues.ToArray();   
  19.         newViewState[1] = base.SaveViewState();  
  20.         return newViewState;  
  21.     }  
  22. protected override void LoadViewState(object savedState)  
  23.     {  
  24.         //if we can identify the custom view state as defined in the override for SaveViewState  
  25.         if (savedState is object[] && ((object[])savedState).Length == 2 && ((object[])savedState)[0] is string[] )  
  26.         {  
  27.            object[] newViewState = (object[])savedState;  
  28.             string[] txtValues = (string[])(newViewState[0]);  
  29.             if (txtValues.Length > 0)  
  30.             {   
  31.                 //re-load tables  
  32.                 CreateDynamicTable();  
  33.                 int i = 0;  
  34.                 foreach (TableRow row in tbl.Controls)  
  35.                 {  
  36.                     foreach (TableCell cell in row.Controls)  
  37.                     {  
  38.                         if (cell.Controls[0] is TextBox && i < txtValues.Length)  
  39.                         {  
  40.                             ((TextBox)cell.Controls[0]).Text = txtValues[i++].ToString();  
  41.   
  42.                         }  
  43.                     }  
  44.                 }  
  45.             }  
  46.             //load the ViewState normally  
  47.             base.LoadViewState(newViewState[1]);  
  48.         }  
  49.         else  
  50.         {  
  51.             base.LoadViewState(savedState);  
  52.         }  
  53.     }  


Hurray.. Now you can access dynamic control value on button click.



VS 2010 for Web Developer - Videos

0 comments

To start off  I thought it would be great to share various videos which are available to view online today ... It will be helpful to all my peers and collegues.

Visual Studio 2010 - Web Development Overview

In this talk we provided the glimpse of the major investment areas in VS 2010.  The talk is divided into following key areas

  • Design View - Improved CSS 2.1 Support &  standards compliance
  • Source View
    • HTML Snippets
    • JScript Intellisense
  • Web Deployment
    • Web.Config Transformation
    • Web 1-Click Publish

Jeff did a great presentation at PDC on this topic which can be viewed at the link below:

http://channel9.msdn.com/pdc2008/TL48/ (77.32 mins)

I also presented a similar talk at TechEd EMEA which is available for viewing below:

 

http://www.vimeo.com/2667207 (62.42 mins)

Visual Studio 2010 - Web Deployment

In this talk we talk about Web Deployment in detail and how next wave of Web Deployment technologies will make deployment a much easier task.  The key focus areas of this talk are:

  • Web Packaging - Packaging your web applications into .zip files
  • Web.Config Transformation - Transforming your web.config file (i.e. connection string, debug flags etc) from dev environment to production environment
  • DB Deployment - Packaging and deploying your SQL Server databases along with your web application
  • Web Publishing - Using Web 1-Click Publish functionality to deploy your web application with ease.

I did a presentation on web deployment at PDC and TechEd EMEA; the PDC presentation can be viewed at the below link:

http://channel9.msdn.com/pdc2008/PC33/  (84.42 mins)

If you would like to see a more compressed version of the talk then I also did a talk with Jason Olson in Visual Studio 2010 and the .NET Framework 4.0 Week! you can view this video at the below link:

http://channel9.msdn.com/posts/VisualStudio/Web-Development-and-Deployment-with-Visual-Studio-2010/ (34.40 mins)

Hope you will enjoy these videos...



Visual Studio has the ability to validate your markup and CSS for standards compliance alongside your code.

0 comments

New VS2008 Feature: “Downgrade” HTML, CSS, and JScript Errors to Warnings

VS2005 introduced the ability to validate your markup and CSS for standards compliance alongside your code.  It’s a great feature, but it can be frustrating when you’re looking for that one critical compilation error underneath a pile of validation errors.  Well, we heard your feedback and added two new options in VS2008 (post-Beta 2): 1) “downgrade” HTML/CSS errors to warnings, 2) “downgrade” JScript errors to warnings.

The Two New Options

The VS2005 Default Experience

The VS2008 Default Experience

We hope this will separate the validation clutter way from what is stopping your build.  You can visually distinguish the warnings from the errors in the text editor as the warnings use green squiggles.  It’s worthwhile to note that both options also (implicitly) “downgrade” your warnings to messages.  Messages will be displayed with no squiggles.  Also note that, while the two options live underneath the “HTML” section, they will also affect your standalone CSS or JS files.  Should you prefer the VS2005 approach of “everything” as errors, un-checking the two options will bring you back to the exact same behavior you had before.



Microsoft Visual J# and other Late Breaking QuickStart Tutorials

0 comments

Welcome to the Microsoft .NET Framework SDK QuickStart Tutorials

The QuickStart Tutorials are the fastest way to understand what the .NET Framework technology offers leading-edge developers. Inside you'll find information about the most compelling features of the .NET Framework technology, including how to put them immediately to work for you or your company. To get started, follow the

The ASP.NET QuickStart

ASP.NET is a rich programming framework for building web-based applications. It offers outstanding support for both developers and administrators, providing improved ease-of-use, tool support, reliability, scalability, administration and security. The ASP.NET QuickStart walks through a series of sample code and concepts to teach you how to make the most of this powerful technology.
arrow forward Start the ASP.NET QuickStart Tutorial

The ASP.NET Web Services QuickStart

ASP.NET Web Services is an extensible, robust platform for building interoperable Web services using the .NET Framework. It offers a simple and easy-to-use out of the box experience, enabling newcomers to Web services to build and deploy their first Web service within minutes. In this release our industry-leading level of interoperability and adherence to industry standards continues with out of the box support for the WS-I Basic Profile.
arrow forward Start the ASP.NET Web Services QuickStart Tutorial


Late breaking QuickStart Tutorials are available on the web. This site includes Visual J# QuickStart Tutorials as well as other samples available after the release of the SDK. There is no guarantee that all of the tutorials found on this site meet the same quality standards as those found in the SDK.
arrow forward Start the Late Breaking QuickStart Tutorials


Free Web Hosting to try ASP.NET 4 Beta1, VS 2010 Beta1 and MS Web Deployment Tool RC1

0 comments

Free Web Hosting to try ASP.NET 4 Beta1, VS 2010 Beta1 and MS Web Deployment Tool RC1
Today we are announcing the availability of FREE HOSTING accounts for web developers to try out the new feature sets of Visual Studio 2010 Beta1, ASP.NET 4 Beta1 and Microsoft Web Deployment Tool (MsDeploy) RC1… VS 2010 has great set of features on deploying Read More...

ASP.NET MVC Framework Preview 2 (Mix 2008) Resources

0 comments

I am attempting to compile the relevant resources for ASP.NET MVC Framework Preview 2 at one place so that you will not have to keep searching around...ALL ASP.NET Resources in one Site.All the best.

ASP.NET MVC Preview 2 Download Location:

Preview 2 Download (English-US) - Microsoft.com download location to get the latest MVC bits...

ASP.NET MVC Documentation:

Home Page - Asp.Net home page where you can find latest updates on ASP.NET MVC Framework in general...  

User Documentation - The official Microsoft user documentation on ASP.NET MVC Framework...

Readme File  - Contains a ton of information on how to install the preview 2 and how can it play well if you already have MVC Framework Preview 1, Silverlight etc...

ASP.NET MVC Learning

Forums - There is a ton of activity on ASP.NET MVC Framework forums, this is a great way of getting your questions answered...  

Videos - There are some great quick start videos on ASP.NET MVC Framework available here, we will be adding more videos here going forward to do keep checking

ASP.NET MVC Blogs

  • Scottgu's Tutorials Root - Scottgu has a bunch of very walk-through on ASP.NET MVC Framework here...
  • ASP.NET Tooling Overview - In this post I have explained the tooling features for ASP.NET MVC Framework...
  • MVC Unit Test Framework Integration - In this post I have explained how you can integrate a new test framework like NUnit, MBUnit, xUnit etc into your MVC Application. 
  • NUnit & Rhino Mocks Integration - In this post Joe has taken a NUnit and Rhino Mocks framework as an example and he has created a Test Project Template for you to download... I will highly encourage you to check this out...
  • Phil Haack's Blog - Phil keeps writing interesting posts about ASP.NET MVC Framework...  It would be nice to routinely check his blog too...
  • My Blog - I also intend to keep posting ASP.NET MVC Framework articles on my blog regularly so you might want to check that out too...
  • Scott Hanselman's Blog - Scott has some ASP.NET MVC Zen stuff on his blog too, do find time to check that out...

ASP.NET MVC CodePlex Source Code

Hope this helps...



Visual Basic Build Performance HotFix to fixes error and enhance performance

0 comments

Visual Basic Build Performance HotFix

The Visual Basic team has released several hotfixes for compilation performance issues with large VB projects.  You can learn how to obtain these hotfixes immediately from this blog post.



Optimizing ASP.NET 2.0 Web Project Build Performance with MS VisualStudio

0 comments

Tip/Trick: Optimizing ASP.NET 2.0 Web Project Build Performance with Microsoft Visual Studio

This posts covers how to best optimize the build performance with Visual Studio 2005 when using web projects.  If you are experiencing slow builds or want to learn how to speed them up please read on.

Quick Background on VS 2005 Web Site Project and VS 2005 Web Application Project options

VS 2005 supports two project-model options: VS 2005 Web Site Projects and VS 2005 Web Application Projects

VS 2005 Web Site Projects were built-in with the initial VS 2005 release, and provide a project-less based model for doing web development that uses that same dynamic compilation system that ASP.NET 2.0 uses at runtime.  VS 2005 Web Application Projects were released as a fully supported download earlier this spring, and provide a project model that uses a MSBuild based build system that compiles all code in a project into a single assembly (similar to VS 2003 -- but without many of the limitations that VS 2003 web projects had with regard to FrontPage Server Extensions, IIS dependencies, and other issues).  To learn more about VS 2005 Web Application Projects, please review the tutorials I've published on my http://webproject.scottgu.com web-site.  Note that VS 2005 Web Application Project support will be included in VS 2005 SP1 (so no additional download will be required going forward).

Both the VS 2005 Web Site Project option and the VS 2005 Web Application Project option will continue to be fully supported going forward with future Visual Studio releases.  What we've found is that some people love one option, while disliking the other, and vice-versa.  From a feature perspective there is no "one best option" to use - it really depends on your personal preferences and team dynamics as to which will work best for you.  For example: a lot of enterprise developers love the VS 2005 Web Application option because it provides a lot more build control and team integration support, while a lot of web developers love the VS 2005 Web Site model because of its "just hit save" dynamic model and flexibility.

Two articles you might find useful to decide which works best for you is this MSDN whitepaper that includes some comparisons between the two models, and Rick Strahl's Web Application Projects and Web Deployment Projects are Here article that provides a good discussion of the pros/cons of the different options.

To migrate from the VS 2005 Web Site Project model to the VS 2005 Web Application Project model, please follow this C# or VB tutorial that walks-through the steps for how to-do so.

So Which Project Option Builds Faster?

When doing full builds of projects, the VS 2005 Web Application Project option will compile projects much faster that the VS 2005 Web Site Project option.  By "full build" I mean cases where every class and page in a project is being compiled and re-built - either because you selected a "Rebuild" option within your "build" menu, or because you modified code within a dependent class library project or in the /app_code directory and then hit "build" or "ctrl-shift-b" to compile the solution. 

There are a few reasons why the VS 2005 Web Application Project ends up being significantly faster than Web Site Projects in these "full rebuild" scenarios.  The main reason is that (like VS 2003), the VS 2005 Web Application Project option only compiles your page's code-behind code and other classes within your project.  It does not analyze or compile the content/controls/in-line code within your .aspx pages -- which means it does not need to parse those files.  On the downside this means that during compilation it will not check for errors in those files (unlike the VS 2005 Web Site Project option which will identify any errors there).  On the positive side it makes compilations much faster.

So does this mean that you should always use the VS 2005 Web Application Project option to get the fastest build times with large projects?  No -- not necessarily.  One nice feature that you can enable with the VS 2005 Web Site Project option is support for doing "on demand compilation".  This avoids you having to always re-build an entire project when dependent changes are made -- instead you can just re-build those pages you are working on and do it on-demand.  This will lead to significant build performance improvements for your solution, and can give you a very nice workflow when working on very large projects.  I would definitely recommend using this option if you want to improve your build performance, while retaining the flexibility of the web-site model.

The below sections provide specific tutorials for both the VS 2005 Web Site Project Model and the VS 2005 Web Application Project Model on optimization techniques -- including the "on demand compilation" build option I described above.

Specific Tips/Tricks for Optimizing VS 2005 Web Site Project Build Times

When using the VS 2005 Web Site Project model, you can significantly improve build performance times by following these steps:

1) Verify that you are not suffering from an issue I call "Dueling Assembly References".  I describe how to both detect and fix this condition in this blog post.  If you are ever doing a build and see the compilation appear to pause in the "Validating Web Site" phase of compilation (meaning no output occurs in the output window for more than a few seconds), then it is likely that you are running into this problem.  Use the techniques outlined in this blog post to fix it.

2) Keep the number of files in your /app_code directory small.  If you end up having a lot of class files within this directory, I'd recommend you instead add a separate class library project to your VS solution and move these classes within that instead since class library projects compile faster than compiling classes in the /app_code directory.  This isn't usually an issue if you just have a small number of files in /app_code, but if you have lots of directories or dozens of files you will be able to get speed improvements by moving these files into a separate class library project and then reference that project from your web-site instead.  One other thing to be aware of is that whenever you switch from source to design-view within the VS HTML designer, the designer causes the /app_code directory to be compiled before the designer surface loads.  The reason for this is so that you can host controls defined within /app_code in the designer.  If you don't have an /app_code directory, or only have a few files defined within it, the page designer will be able to load much quicker (since it doesn't need to perform a big compilation first).

3) Enable the on-demand compilation option for your web-site projects.  To enable this, right-click on your web-site project and pull up the project properties page.  Click the "Build" tab on the left to pull up its build settings.  Within the "Build" tab settings page change the F5 Start Action from "Build Web Site" to either the "Build Page" or "No Build" option.  Then make sure to uncheck the "Build Web site as part of solution" checkbox:

When you click ok to accept these changes you will be running in an on-demand compilation mode.  What this means (when you select the "Build Page" option in the dialog above) is that when you edit a page and then hit F5 (run with debugging) or Ctrl-F5 (run without debugging) the solution will compile all of the class library projects like before, then compile the /app_code directory and Global.asax file, and then instead of re-verifying all pages within the web-site it will only verify the current page you are working on, and any user controls that the page references.  With large (and even medium) projects with lots of pages, this can obviously lead to major performance wins.  Note that ASP.NET will automatically re-compile any other page or control you access at runtime -- so you will always have an up-to-date and current running application (you don't need to worry about old code running).  You can optionally also use the "No Build" option to by-pass page-level validation in the IDE, which obviously speeds up the entire process much further (I'd recommend giving both options a try to see which you prefer). 

By deselecting the "Build Web site as part of solution" checkbox, you will find that the Ctrl-Shift-B keystroke (which builds the solution) will continue compiling all class library projects, but will not re-build all pages within your web-site project.  You will still get full intellisense support in your pages in this scenario - so you won't lose any design-time support.  You will also continue to get warning/error squiggles in code/class when they are open.  If you want a way to force a re-build to occur on pages not open, or across all pages within the web-site, you can use the "Build Page" or "Build Web Site" menu options within the "Build" menu of Visual Studio:

This gives you control as to which pages on your site you want to verify (and when) - and can significantly improve build performance.  One trick I recommend doing is adding a new shortcut keystroke to your environment to allow you to quickly short-cut the "Build Page" menu option to avoid you having to ever use a mouse/menu for this.  You can do this by selecting the Tools->Customize menu item, and then click the "Keyboards" button on the bottom-left of the customize dialog.  This will bring up a dialog box that allows you to select the VS Build.BuildPage command and associate it within any keystroke you want:

Once you do this, you can type "Ctrl-Shift-P" (or any other keystroke you set) on any page to cause VS to compile any modified class library project (effectively the same thing that Ctrl-Shift-B does), then verify all classes within the /app_code directory, and then re-build just the page or user control (and any referenced master pages or user controls it uses) that you are working on within the project.

Once the above steps are applied, you should find that your build performance and flexibility is much improved - and that you have complete control over builds happen.

Specific Tips/Tricks for Optimizing VS 2005 Web Application Project Build Times

If you are using the VS 2005 Web Application project option, here are a few optimizations you might want to consider:

1) If you have a very large project, or are working on an application with many other developers, you might want to consider splitting it up into multiple "sub-web" projects.  I wouldn't necessarily recommend this for performance reasons (unless you have thousands and thousands of pages it probably doesn't make a huge difference), but it can sometimes make it easier to help manage a large project.  Please read this past blog-post of mine on creating sub-web projects to learn how to use this.

2) Consider adding a VS 2005 Web Deployment project to your solution for deep verification.  I mentioned above that one downside of using the VS 2005 Web Application Project option was that it only compiled the code-behind source code of your pages, and didn't do a deeper verification of the actual .aspx markup (so it will miss cases where you have a mis-typed tag in your .aspx markup).  This provides the same level of verification support that VS 2003 provided (so you aren't loosing anything from that), but not as deep as the Web Site Project option.  One way you can still get this level of verification with VS 2005 Web Application Projects is to optionally add a VS 2005 Web Deployment Project into your solution (web deployment projects work with both web-site and web-application solutions).  You can configure this to run only when building "release" or "staging" builds of your solution (to avoid taking a build hit at development time), and use it to provide a deep verification of both your content and source code prior to shipping your app. 

Common Tips/Tricks for Optimizing any VS 2005 Build Time

Here are a few things I recommend checking anytime you have poor performance when building projects/solutions (note: this list will continue to grow as I hear new ones - so check back in the future):

1) Watch out for Virus Checkers, Spy-Bots, and Search/Indexing Tools

VS hits the file-system a lot, and obviously needs to reparse any file within a project that has changed the next time it compiles.  One issue I've seen reported several times are cases where virus scanners, spy-bot detecters, and/or desktop search indexing tools end up monitoring a directory containing a project a little too closely, and continually change the timestamps of these files (they don't alter the contents of the file - but they do change a last touched timestamp that VS also uses).  This then causes a pattern of: you make a change, rebuild, and then in the background the virus/search tool goes in and re-searches/re-checks the file and marks it as altered - which then causes VS to have to re-build it again.  Check for this if you are seeing build performance issues, and consider disabling the directories you are working on from being scanned by other programs.  I've also seen reports of certain Spybot utilities causing extreme slowness with VS debugging - so you might want to verify that you aren't having issues with those either.

2) Turn off AutoToolboxPopulate in the Windows Forms Designer Options

There is an option in VS 2005 that will cause VS to automatically populate the toolbox with any controls you compile as part of your solution.  This is a useful feature when developing controls since it updates them when you build, but I've seen a few reports from people who find that it can cause VS to end up taking a long time (almost like a hang) in some circumstances.  Note that this applies both to Windows Forms and Web Projects.  To disable this option, select the Tools->Options menu item, and then unselect the Windows Forms Designer/General/AutoToolboxPopulate checkbox option (for a thread on this see: http://forums.asp.net/1108115/ShowPost.aspx).

3) Examine which 3rd party packages are running in Visual Studio

There are a lot of great 3rd party VS packages that you can plug into Visual Studio.  These deliver big productivity wins, and offer tons of features.  Occasionally I've seen issues where performance or stability is being affected by them though.  This is often true in cases where an older version (or beta) of one of these packages is being used (always keep an eye out for when a manufacturer updates them with bug-fixes).  If you are seeing issues with performance or stability, you might want to look at trying a VS configuration where you uninstall any additional packages to see if this makes a difference.  If so, you can work with the 3rd party manufacturer to identify the issue. 



Web.Config Files in Asp.net

0 comments

Clean Web.Config Files (VS 2010 and .NET 4.0 Series)

This is the first in a series of blog posts I’m doing on the upcoming VS 2010 and .NET 4 release.

Today’s post is about an admittedly small, but I still think kind of nice, change coming with ASP.NET 4.0: clean, simple, web.config files. 

You’ll encounter this improvement the first time you do a File->New Project within Visual Studio 2010 and create an empty ASP.NET 4.0 Web application (which is why I thought it might be appropriate to-do as the first post).

Web.config files in .NET 3.0 and 3.5

Over the last few releases, the web.config files within new ASP.NET projects have steadily increased in size. For example: the default web.config file that is added to a new web project in Visual Studio 2008 SP1 is now some 126 lines long, and contains everything from tag definitions to definitions of handlers and modules to be included in the ASP.NET HTTP pipeline.

This increase in size is because .NET 3.0 and .NET 3.5 use the same CLR and machine.config configuration file as those shipped with .NET 2.0 – and simply add and update assemblies in the framework when they are installed.  To avoid the risk of us accidentally overwriting customized settings within the original 2.0 machine.config on the machine, we didn’t register the tag definitions, handlers and modules that shipped with the new ASP.NET functionality that came with the .NET 3.0 and .NET 3.5 versions.  Instead, we defaulted to having new projects register these settings within the application’s local web.config file instead.  This was safer – but caused the web.config files to increase and become more complicated and harder to read.

Web.config files in .NET 4

.NET 4 includes a new version of the CLR, and a new .NET 4 specific machine.config file (which is installed side-by-side with the one used by .NET 2, .NET 3 and .NET 3.5).

The new .NET 4 machine.config file now automatically registers all of the ASP.NET tag sections, handlers and modules that we’ve added over the years, including the functionality for:

  • ASP.NET AJAX
  • ASP.NET Dynamic Data
  • ASP.NET Routing (which can now be used for both ASP.NET WebForms and ASP.NET MVC)
  • ASP.NET Chart Control (which now ships built-into ASP.NET V4)

What this means is that when you create a new “Empty ASP.NET application” project in VS 2010, you’ll find that the new default application-level web.config file is now clean and simple:

The first config section above just tells ASP.NET to enable debugging by default for the application, and indicates the version of .NET that Visual Studio should target when it provides intellisense (VS 2010 supports multi-targeting – and the intellisense within the IDE will automatically vary depending on which version of the framework you are targeting).

The second config section indicates whether to use “integrated” mode when running the ASP.NET application within IIS7 – which controls whether to run ASP.NET HttpModules for all requests within the application or just for the ASP.NET specific URLs.  We enable this by default at the application level web.config file for new applications – since for compatibility reasons the default IIS7 setting registered at the machine-wide is to run modules only for ASP.NET URLs (and not for all requests).

Summary

The simplified web.config file in .NET 4 is an admittedly small change – but I think a nice one nonetheless, and one which makes the default experience when you create a new ASP.NET application a little cleaner and more approachable.

In the posts ahead I’ll be delving into many of the more substantial improvements coming with ASP.NET 4. (as well as a few more of the “small but nice tweaks” coming too)



Starter Project Templates in ASP.NET Project

0 comments

Starter Project Templates (VS 2010 and .NET 4.0 Series)

This is the second in a series of blog posts I’m doing on the upcoming VS 2010 and .NET 4 release.

Today’s post is about another small, but I think nice, change coming with VS 2010 and ASP.NET 4 when you create new ASP.NET Web projects – which is the ability to create both “Empty projects” as well as to create projects that already have some layout and common functionality included in them, and which can help you get started when building a new application.

Creating New Projects

When you use the File->New Project or File->New Web Site menu commands within VS 2010, you’ll see a “New Project” dialog like below that allows you to filter by language and application type and select different project templates to use when creating new projects:

newproject1

VS 2010 ships with “empty” project templates for creating new ASP.NET applications – which will create minimal projects with just the bare essentials needed to get going.  My last post in this series included a screenshot that shows what the “Empty ASP.NET Web Application” project template creates when you use it to start a new application.

Creating a New Project using a Starter Template

VS 2010 also ships with starter template projects that allow you to create a new ASP.NET application that has some layout/CSS structure and common functionality already implemented within it. 

We first tried this concept with ASP.NET MVC 1.0 – whose project template provides a master page, CSS file, JavaScript libraries, login system, and a “home” and “about” page already wired up and implemented.  VS 2010 adds support for this idea when creating new ASP.NET Web Forms projects as well. 

When you choose the default “ASP.NET Web Application” project template, you’ll find that the ASP.NET Web Forms project created already has some directories and files contained within it:

template1

It includes a Site.Master master page file that provides an overall layout for the site (with headers, footers, etc), and which uses a CSS stylesheet for all styles.  It has a “Scripts” directory that contains jQuery within it (ASP.NET AJAX is available via the script manager control).  It includes a “default.aspx” and “about.aspx” pages in the root directory that are based on the master page and include some boiler plate content.  And it includes an “Account” directory that has some pages that implement a forms-based authentication system for users to log-in, register and change their passwords:

template2

You can run the project without having to write any code or configure anything, and get a nice site up and running:

template3

The site has full support for forms based security authentication, and is pre-wired up to use the ASP.NET Membership system for password management:

template4

All of the styles and content within the site are configured using CSS, and take advantage of some of the new features with Web Forms in ASP.NET 4 – including clean client-side “id” names (no more ctrl_ mangled names – ASP.NET 4 gives you complete control over the client id), and CSS based rendering instead of table based rendering for the built-in server controls.  I’ll discuss these new Web Forms features in a lot more depth in later posts in this series (along with a lot of other features being added).

Online Template Gallery

In addition to the built-in project templates, VS 2010 also support the ability when inside the “New Project” and “Add Item” dialogs to search an online gallery of additional templates to use.  You can contribute your own templates to the gallery, rate and review submissions of others, and search and filter them by project type, keyword and community rating.  You can then easily download and install any template locally directly within the dialog:

template5

This will hopefully facilitate the creation of lots of useful project starter kits (of all types of projects – not just web) that people can easily discover and use to quickly get going when building solutions.

Hope this helps,



Some Useful Books

http://books.google.com.np/books?id=Lan3g76cCFYC&lpg=PP1&dq=photoshop%20shortcuts&hl=en&pg=PT1#v=onepage&q=photoshop%20shortcuts&f=false

About Me

SubscribeSubscribe via RSS

SubscribeRecent Posts

SubscribeHot Links

Archive

Live Traffic Feed