| DotNetKicks.com Links |
| Organize ASP.MVC Controllers in Namespace and specific Urls ... Distribute your ASP.NET MVC controllers in namespaces and subfolders and ensure the controllers can only be access from specific subfolder. For example, controllers that belong to MvcWebAPI.Admin.User can only be accessed from /MvcWebAPI/Admin/User not from /MvcWebAPI/User. | Go |
| How ASP.NET began in Java ... "ASP.NET happened after we shipped IIS 4.0 and everyone went on vacation. Scott Guthrie and I - Scott worked for me at the time, he was 22 years old, straight out of college - and we took advantage of the time everyone was on vacation to start brainstorming new ideas. We looked at ASP and how it was being used. I had worked on Visual InterDev so I had a lot of friends on that team, and we were looking at the new version, I think it was Visual InterDev 6.0, and we noticed how messy the code was. We said, how can we do better? Scott and I worked for a month and a half, and then when everybody came back from vacation in January we showed them a prototype and a PowerPoint deck, showed them this vision, and people said, 'keep working on it'." | Go |
| Create REST API using ASP.NET MVC that speaks both Json and Xml ... MvcWebAPI is a collection of library that helps creating RESTful Web API for your website. You can directly return objects or collections from controllers. The library takes care of property serializing them into Json or plain Xml. The library also allows Action methods to consume objects or collections directly as it takes care of underlying deserialization from Json or Xml. | Go |
| ASP.NET MVC Tip: Ajax and Validations using jQuery ... In this post, I demonstrate how to integrate jQuery with ASP.NET MVC and will be explain how to send Ajax requests and also show client side validation using jQuery. I am using a blog application for this demo and it will show how to post a comment of a blog entry using Ajax request and will also show partial rendering with the help of a user control. | Go |
| Versioned Assemblies for Precompiled ASP.NET Web Sites ... There's a good article about how to create versioned assemblies for precompiled ASP.NET web sites. | Go |
| Introduction to the MagicAjax.NET - The Magic Ajax Engine for .NET ... MagicAjax.NET is a free open-source framework, designed to make it easier and more intuitive for developers to integrate AJAX technology into their web pages, without replacing the ASP.NET controls and/or writing tons of JavaScript code. | Go |
| VistaDB Provider for MPS ... VistaDB providers for my personal site | Go |
| BlogService MVC Release 0.6 ... This release marks the change over to ASP.NET MVC framework. BlogSvc aims to be THE blog engine for new technology. MVC has greatly reduced complexity and increased testability of BlogSvc. With this release the BlogSvc.net website was separated out of the WebMvc project. The MVC switch also allowed for improvements with jQuery. | Go |
| Using the ASP.NET MVC ModelBinder attribute - Second part ... Just after the ASP.NET MVC preview 5 was released, I made a quick attempt to using the ModelBinder attribute. In short, a ModelBinder allows you to use complex objects as action method parameters, instead of just basic types like strings and integers. While my aproach was correct, it did not really cover the whole picture. So here it is: the full picture. | Go |
| JQuery and ASP.NET MVC ... Where have I been? ;) You probably heard the news already from the GU already, but just in case, we will be shipping JQuery with Visual Studio. ASP.NET MVC will have the privilege of being one of the first products to include JQuery. I am glad we finally announced this because I got tired of stifling my mouth everytime someone suggested we just | Go |
| October 2nd Links: ASP.NET, ASP.NET MVC, ASP.NET Dynamic Data ... Here is the latest in my link-listing series. Also check out my ASP.NET Tips, Tricks and Tutorials page and Silverlight Tutorials page for links to popular articles I've done myself in the past. | Go |
| ASP.NET - Response time is very slow for the first request to applicat ... ASP.NET - Response time is very slow for the first request to application (45+ seconds) | Go |
| ASP.NET E-Mail Validation Using The Right Validation Expression ... ASP.NET E-Mail Validation With Regular Expression Validator Using The Right Validation Expression | Go |
| Removing unused CSS Classes from your web application ... 2 ways to clean up your Css by removing unused classes. | Go |
| Delicious tagged ASP.NET Links |
| Scott Hanselman's Computer Zen - jQuery to ship with ASP.NET MVC and Visual Studio | Go |
| How do we write test automation for ASP.NET? - Asp.Net QA Team | Go |
| jQuery and Microsoft - ScottGu's Blog | Go |
| An Introduction to jQuery - Part 1: The Client Side | Go |
| Scott Hanselman's Computer Zen - Plug-In Hybrids: ASP.NET WebForms and ASP.MVC and ASP.NET Dynamic Data Side By Side | Go |
| CodeThinked | ASP.NET MVC Request Flow | Go |
| URL Rewriting in ASP.NET using URLRewriter.Net | Go |
| Adding OpenID to your web site in conjunction with ASP.NET Membership - Digging My Blog - Dan Hounshell | Go |
| Site AuctionOffer.com | Go |
| My MVC Starter Template : Rob Conery | Go |
| Scott Gu Blog Links |
| October 2nd Links: ASP.NET, ASP.NET MVC, ASP.NET Dynamic Data ... Here is the latest in my link-listing series . Also check out my ASP.NET Tips, Tricks and Tutorials page and Silverlight Tutorials page for links to popular articles I've done myself in the past. ASP.NET Amazon EC2 Support for Windows and ASP.NET: Big news announced this week: Amazon will be offering Windows Server 2008 as an option in their EC2 service. This enables you to use ASP.NET, IIS7 and SQL Server in the cloud. Using ASP.NET WebForms, MVC and Dynamic Data in a Single Application : Scott Hanselman has a nice post that demonstrates how you can have a single ASP.NET application that uses ASP.NET WebForms, MVC, WebServices and Dynamic Data. You have the flexibility to mix and match them however you want, which allows you to always use the right tool depending on the specific job. Modifying Data with the ListView's EditItemTemplate : Matt Berseth has a great post that talks about how to use the ASP.NET 3.5 ListView control to enable in-place editing scenarios - with total html markup control. 4 New Grouping Grid Skins: Vista, Bold, Win2k3 and Soft : Matt Berseth has another nice post that demonstrates how to skin the ASP.NET ListView control to enable some sweet data grouping scenarios. Unlocking and Approving User Accounts : Scott Mitchell posts another in his great series of articles on ASP.NET security (click here for all the articles in the series). This article talks about how you can setup administration pages that allow admins to lock out and approve user accounts using the ASP.NET Membership system. Adding OpenID to you website in conjunction to ASP.NET Membership : Dan Hounshell has a nice article that discusses how to add OpenID authentication support to your web-site, and use it in conjunction to ASP.NET's built-in membership system. ASP.NET MVC MVC Membership with Preview 5 : Troy Goode posts an update of his popular MVC Membership template that works with ASP.NET MVC Preview 5. It provides a set of administration pages you can use for user/role management, as well as adds support for OpenID and Windows LiveID. MVC Flickr Xplorer : Mehfuz Hossain has a cool ASP.NET MVC sample application posted that enables a nice picture explorer for FlickR photos. ASP.NET Dynamic Data Simple 5 Table Northwind Example : Matt Berseth kicks off his ASP.NET Dynamic Data tutorial series with a nice post that shows how to build a simple 5 table application using ASP.NET Dynamic Data with .NET 3.5 SP1. Dynamic Data And Custom Metadata Providers : Matt continues the series and covers the MetadataType attribute, and how you can use it to annotate your entities with additional metadata. Dynamic Menu for your Dynamic Data: Matt continues and covers how to add a data-driven menu to the site. Customizing the Delete Confirmation Dialog : Matt continues and demonstrates how to build a nice UI experience when deleting records in a dynamic data application. Experimenting with YUI's DataTable and DataSource Controls : Matt experiments with how to use client-side AJAX components together with dynamic data. Hope this helps, Scott | Go |
| jQuery and Microsoft ... jQuery is a lightweight open source JavaScript library (only 15kb in size) that in a relatively short span of time has become one of the most popular libraries on the web. A big part of the appeal of jQuery is that it allows you to elegantly (and efficiently) find and manipulate HTML elements with minimum lines of code. jQuery supports this via a nice "selector" API that allows developers to query for HTML elements, and then apply "commands" to them. One of the characteristics of jQuery commands is that they can be "chained" together - so that the result of one command can feed into another. jQuery also includes a built-in set of animation APIs that can be used as commands. The combination allows you to do some really cool things with only a few keystrokes. For example, the below JavaScript uses jQuery to find all <div> elements within a page that have a CSS class of "product", and then animate them to slowly disappear: As another example, the JavaScript below uses jQuery to find a specific <table> on the page with an id of "datagrid1", then retrieves every other <tr> row within the datagrid, and sets those <tr> elements to have a CSS class of "even" - which could be used to alternate the background color of each row: [Note: both of these samples were adapted from code snippets in the excellent jQuery in Action book] Providing the ability to perform selection and animation operations like above is something that a lot of developers have asked us to add to ASP.NET AJAX, and this support was something we listed as a proposed feature in the ASP.NET AJAX Roadmap we published a few months ago. As the team started to investigate building it, though, they quickly realized that the jQuery support for these scenarios is already excellent, and that there is a huge ecosystem and community built up around it already. The jQuery library also works well on the same page with ASP.NET AJAX and the ASP.NET AJAX Control Toolkit. Rather than duplicate functionality, we thought, wouldn't it be great to just use jQuery as-is, and add it as a standard, supported, library in VS/ASP.NET, and then focus our energy building new features that took advantage of it? We sent mail the jQuery team to gauge their interest in this, and quickly heard back that they thought that it sounded like an interesting idea too. Supporting jQuery I'm excited today to announce that Microsoft will be shipping jQuery with Visual Studio going forward. We will distribute the jQuery JavaScript library as-is, and will not be forking or changing the source from the main jQuery branch. The files will continue to use and ship under the existing jQuery MIT license. We will also distribute intellisense-annotated versions that provide great Visual Studio intellisense and help-integration at design-time. For example: and with a chained command: The jQuery intellisense annotation support will be available as a free web-download in a few weeks (and will work great with VS 2008 SP1 and the free Visual Web Developer 2008 Express SP1). The new ASP.NET MVC download will also distribute it, and add the jQuery library by default to all new projects. We will also extend Microsoft product support to jQuery beginning later this year, which will enable developers and enterprises to call and open jQuery support cases 24x7 with Microsoft PSS. Going forward we'll use jQuery as one of the libraries used to implement higher-level controls in the ASP.NET AJAX Control Toolkit, as well as to implement new Ajax server-side helper methods for ASP.NET MVC. New features we add to ASP.NET AJAX (like the new client template support ) will be designed to integrate nicely with jQuery as well. We also plan to contribute tests, bug fixes, and patches back to the jQuery open source project. These will all go through the standard jQuery patch review process. Summary We are really excited to be able to partner w | Go |
| Silverlight 2 Release Candidate Now Available ... This evening we published the first public release candidate of Silverlight 2. There are still a small handful of bugs fixes that we plan to make before we finally ship. We are releasing today's build, though, so that developers can start to update their existing Silverlight Beta2 applications so that they'll work the day the final release ships, as well as to enable developers to report any last minute showstopper issues that we haven't found internally (please report any of these on the www.silverlight.net forums). Important: We are releasing only the Silverlight Developer Runtime edition (as well as the VS and Blend tools to support it) today, and are not releasing the regular end-user edition of Silverlight. This is because we want to give existing developers a short amount of time to update their applications to work with the final Silverlight 2 APIs before sites are allowed to go live with it. There are some breaking changes between Beta2 and this RC, and we want to make sure that existing sites can update to the final release quickly once the final release is out. As such, you can only use the RC for development right now - you can't go live with the new APIs until the final release is shipped (which will be soon though). You can download today's Silverlight Release Candidate and accompanying VS and Blend support for it here . Note that Expression Blend support for Silverlight 2 is now provided using Blend 2.0 SP1. You will need to install Blend 2.0 before applying the SP1 service pack that adds Silverlight 2 support. If you don't already have Blend 2.0 installed you can download a free trial of it here . Beta2->RC API Updates Today's release candidate includes a ton of bug fix and some significant performance optimization work. Today's release candidate also includes a number of final API tweaks designed to fix differences between Silverlight and the full .NET Framework. Most of these changes are relatively small (order of parameters, renames of methods/properties, movement of types across namespaces, etc) although there are a number of them. You can read this blog post and download this document to get a listing of the known API breaking changes made from the Beta2 release. We have updated the styles of the controls shipped with Silverlight, and have also modified some of the state groups and control template names they use. When upgrading from Beta2 you might find it useful to temporarily remove any custom style templates you've defined, and get your application functionality working using the RC first - and then after that works add back in the styles one style definition at a time to catch any rename/behavior change issues with them. If you find yourself stuck with an question/issue moving from Beta2 to the RC, please report it on the www.silverlight.net forums (Silverlight team members will be on there helping folks). If after a day or two you aren't getting an answer please send me email (scottgu@microsoft.com ) and I can help or connect you with someone who knows the answer. New Controls Today's release candidate includes a bunch of feature additions and tweaks across Silverlight 2, as well as in the VS and Blend tools targeting it. In general you'll find a number of nice improvements across the controls, networking, data caching, layout, rendering, media stack, and other components and sub-systems. Over the next few months we will be releasing a lot of new Silverlight 2 controls (more details on these soon). Today's release candidate includes three new core controls - ComboBox, ProgressBar, and PasswordBox - that we are adding directly to the core Silverlight runtime download (which is still only 4.6MB in size, and only takes a few seconds to install): At runtime these controls by default look like: The ComboBox in Silverlight 2 supports standard DropDownList semantics. In addition to statically defining items like above, you | Go |
| ASP.NET MVC Preview 5 and Form Posting Scenarios ... This past Thursday the ASP.NET MVC feature team published a new "Preview 5" release of the ASP.NET MVC framework. You can download the new release here . This "Preview 5" release works with both .NET 3.5 and the recently released .NET 3.5 SP1. It can also now be used with both Visual Studio 2008 as well as (the free) Visual Web Developer 2008 Express SP1 edition (which now supports both class library and web application projects). Preview 5 includes a bunch of new features and refinements (these build on the additions in "Preview 4" ). You can read detailed "Preview 5" release notes that cover changes/additions here . In this blog post I'm going to cover one of the biggest areas of focus with this release: form posting scenarios. You can download a completed version of the application I'll build below here . Basic Form Post with a Web MVC Pattern Let's look at a simple form post scenario - adding a new product to a products database: The page above is returned when a user navigates to the "/Products/Create" URL in our application. The HTML form markup for this page looks like below: The markup above is standard HTML. We have two <input type="text"/> textboxes within a <form> element. We then have an HTML submit button at the bottom of the form. When pressed it will cause the form it is nested within to post the form inputs to the server. The form will post the contents to the URL indicated by its "action" attribute - in this case "/Products/Save". Using the previous "Preview 4" release of ASP.NET we might have implemented the above scenario using a ProductsController class like below that implements two action methods - "Create" and "Save": The "Create" action method above is responsible for returning an html view that displays our initial empty form. The "Save" action method then handles the scenario when the form is posted back to the server. The ASP.NET MVC framework automatically maps the "ProductName" and "UnitPrice" form post values to the method parameters on the Save method with the same names. The Save action then uses LINQ to SQL to create a new Product object, assigns its ProductName and UnitPrice values with the values posted by the end-user, and then attempts to save the new product in the database. If the product is successfully saved, the user is redirected to a "/ProductsAdded" URL that will display a success message. If there is an error we redisplay our "Create" html view again so that the user can fix the issue and retry. We could then implement a "Create" HTML view template like below that would work with the above ProductsController to generate the appropriate HTML. Note below that we are using the Html.TextBox helper methods to generate the <input type="text"/> elements for us (and automatically populate their value from the appropriate property in our Product model object that we passed to the view): Form Post Improvements with Preview 5 The above code works with the previous "Preview 4" release, and continues to work fine with "Preview 5". The "Preview 5" release, though, adds several additional features that will allow us to make this scenario even better. These new features include: The ability to publish a single action URL and dispatch it differently depending on the HTTP Verb Model Binders that allow rich parameter objects to be constructed from form input values and passed to action methods Helper methods that enable incoming form input values to be mapped to existing model object instances within action methods Improved support for handling input and validation errors (for example: automatically highlighting bad fields and preserving end-user entered form values when the form is redisplayed to the user) I'll use the remainder of this blog post to drill into each of these scenarios. [AcceptVerbs] and [ActionName] attributes In our sample above we implemented ou | Go |
| Quick Update ... I've received a number of (very nice) emails recently asking if I was ok - since my blog has been silent the last few weeks (and much of the summer). Just to address people's concerns - I'm alive and well. :-) I've just been on vacation the last 6 weeks, and have unfortunately not had free time to post (I've been changing a lot of diapers). I am still on vacation another week before I officially return to work. I did get a chance to write up a quick post this weekend that covers some of the new ASP.NET MVC Preview 5 features, though, that will hopefully provide some interim reading until I can resume a more regular posting schedule over the next month when I get back into the office. Thanks, Scott P.S. Somewhat to my embarrassment I started a Part1/Part2 post on "Preview 4" right before I left for vacation, and didn't have time to finish part 2 before "Preview 5" came out. I am going to post this lost segment (which covered AJAX) later this month and write it against the latest preview build. P.P.S. People often ask me whether I write my own blog. Yep - I actually really do write every single post. Hopefully my absence the last 6 weeks provides some evidence to support this. :-) | Go |
| ASP.NET MVC Preview 4 Release (Part 1) ... The ASP.NET MVC team is in the final stages of finishing up a new "Preview 4" release that they hope to ship later this week. The Preview 3 release focused on finishing up a lot of the underlying core APIs and extensibility points in ASP.NET MVC. Starting with Preview 4 this week you'll start to see more and more higher level features begin to appear that build on top of the core foundation and add nice productivity. There are a bunch of new features and capabilities in this new build - so much in fact that I decided I needed two posts to cover them all. This first post will cover the new Caching, Error Handling and Security features in Preview 4, as well as some testing improvements it brings. My next post will cover the new AJAX features being added with this release as well. Understanding Filter Interceptors Action Filter Attributes are a useful extensibility capability in ASP.NET MVC that was first added with the "Preview 2" release. These enable you to inject code interceptors into the request of a MVC controller that can execute before and after a Controller or its Action methods execute. This enables some nice encapsulation scenarios where you can easily package-up and re-use functionality in a clean declarative way. Below is an example of a super simple "ScottGuLog" filter that I could use to log details about exceptions raised during the execution of a request. Implementing a custom filter class is easy - just subclass the "ActionFilterAttribute" type and override the appropriate methods to run code before or after an Action method on the Controller is invoked, and/or before or after an ActionResult is processed into a response. Using a filter within a ASP.NET MVC Controller is easy - just declare it as an attribute on an Action method, or alternatively on the Controller class itself (in which case it will apply to all Action methods within the Controller): Above you can see an example of two filters being applied. I've indicated that I want my "ScottGuLog" to be applied to the "About" action method, and that I want the "HandleError" filter to be applied to all Action methods on the HomeController. Previous preview releases of ASP.NET MVC enabled this filter extensibility, but didn't ship with pre-built filters. ASP.NET Preview 4 now includes several useful filters for handling output caching, error handling and security scenarios. OutputCache Filter The [OutputCache] filter provides an easy way to integrate ASP.NET MVC with the output caching features of ASP.NET (with ASP.NET MVC Preview 3 you had to write code to achieve this). To try this out, modify the "Message" value set within the "Index" action method of the HomeController (created by the VS ASP.NET MVC project template) to display the current time: When you run your application you'll see that a timestamp updates each time you refresh the page: We can enable output caching for this URL by adding the [OutputCache] attribute to the our Action method. We'll configure it to cache the response for a 10 second duration using the declaration below: Now when you hit refresh on the page you'll see that the timestamp only updates every 10 seconds. This is because the action method is only being called once every 10 seconds - all requests between those time intervals are served out of the ASP.NET output cache (meaning no code needs to run - which makes it super fast). In addition to supporting time duration, the OutputCache attribute also supports the standard ASP.NET output cache vary options (vary by params, headers, content encoding, and custom logic). For example, the sample below would save different cached versions of the page depending on the value of an optional "PageIndex" QueryString parameter, and automatically render the correct version depending on the incoming URL's querystring value: You can also integrate with the ASP.NET Database Cache Invalidation feature - which allows you t | Go |
| Silverlight 2 Beta2 Released ... Silverlight 2 Beta2 was released today. You can download both Silverlight 2 Beta2 and the Visual Studio and Expression Blend tools support to target it here . Beta2 adds a lot of new features (more details below), but is still a 4.6 MB download that takes less than 10 seconds to install on a machine. It does not require the .NET Framework or any other software to be installed for it to work, and all features work cross-browser on both Mac and Windows machines. These features will also be supported on Linux via the Moonlight 2 release. Silverlight 2 Beta2 supports a go-live license that allows you to start using and deploying Silverlight 2 for commercial applications. There will be some API changes between Beta2 and the final release, so you should expect that applications you write with Beta2 will need to make some updates when the final release comes out. But we think that these changes will be straight-forward and relatively easy, and that you can begin planning and starting commercial projects now. You can build Silverlight Beta2 applications using the VS 2008 Tools for Silverlight and Expression Blend 2.5 June Preview downloads. You can download both of them here . The VS 2008 Tools for Silverlight download works with both VS 2008 and the recent VS 2008 SP1 beta release. UI and Control Improvements Silverlight 2 Beta2 includes a bunch of work in the UI and Control space: More Built-in Controls In Beta 1 only a few controls were included with the core Silverlight setup. Most common controls (including Button, ListBox, Slider, etc) were shipped within separate assemblies that you had to bundle with your applications (which increased the app download size). Beta 2 now installs 30+ of the most common controls as part of the core Silverlight 2 download. This means that you can now build Silverlight 2 applications that use core controls that are as small as 3kb in size - making Silverlight application downloads small and startup time fast. In addition to the core controls included with the base Silverlight 2 setup, we are also this week shipping additional higher-level controls that are implemented in separate assemblies that you can then reference and include with your applications. This includes controls like DataGrid (more details on its new Beta2 features below), Calendar (now with multi-day selection and blackout date support in Beta2), and a TabPanel control (new in Beta2). We ultimately expect to ship over a 100 controls for Silverlight. Control Template Editing Support One of the most powerful features of the WPF and Silverlight programming model is the ability to completely customize the look and feel of controls. This allows developers and designers to sculpt the UI of controls in both subtle and dramatic ways, and enables a tremendous amount of flexibility. I covered these concepts a little in my previous Silverlight Control Templating blog post here . This week's Expression Blend 2.5 June Preview now adds designer support for editing control templates - which makes it easy for you to quickly change the look of any control without having to drop-down to XAML source to-do it. To see control template editing in action, just drag/drop two Slider controls onto the Expression Blend design surface: We might decide that the slider head in the default Slider control template is too large and wide for our application. To use control template editing to change it, we can right-click on one of the sliders in the designer and select the "Edit Control Parts" context menu item. We can choose to create a new empty control template for our slider (and start from scratch), or alternatively edit a copy of the built-in control template (and start from that and tweak it): After we choose to edit a copy of the existing control template, Blend will prompt us to create and name a re-usable style resource that we'll define our control template wit | Go |
| ASP.NET MVC Support with Visual Web Developer 2008 Express ... Last week I blogged about the ASP.NET MVC Preview 3 release . One important thing I forgot to mention about this release is that you can now use it with both Visual Studio 2008 as well as the free Visual Web Developer 2008 Express edition. The SP1 release of Visual Web Developer 2008 Express adds support for both class library projects as well as web application projects (previously only web site projects could be used with it). This new support is useful in itself, as well as in enabling both ASP.NET MVC and Silverlight project support with VWD Express. If you install the Visual Web Developer Express SP1 Beta you can start using ASP.NET MVC Preview 3 with it immediately. Important: ASP.NET MVC Preview 3 does not require SP1 to be installed if you are using Visual Studio 2008. ASP.NET MVC Preview 3 will work with both VS 2008 and VS 2008 SP1 just fine. You can learn more about the new VWD Express support for ASP.NET MVC from the VS Web Tools team blog here . This post also includes a free web download that provides ASP.NET MVC Test project support for NUnit-based unit tests. You can use these NUnit project templates with both Visual Studio 2008 as well as with Visual Web Developer Express 2008. Hope this helps, Scott | Go |
| ASP.NET MVC Preview 3 Release ... This morning we released the Preview 3 build of the ASP.NET MVC framework. I blogged details last month about an interim source release we did that included many of the changes with this Preview 3 release. Today's build includes some additional features not in last month's drop, some nice enhancements/refinements, as well as Visual Studio tool integration and documentation. You can download an integrated ASP.NET MVC Preview 3 setup package here . You can also optionally download the ASP.NET MVC Preview 3 framework source code and framework unit tests here . Controller Action Method Changes ASP.NET MVC Preview 3 includes the MVC Controller changes we first discussed and previewed with the April MVC source release , along with some additional tweaks and adjustments. You can continue to write controller action methods that return void and encapsulate all of their logic within the action method. For example: which would render the below HTML when run: Preview 3 also now supports using an approach where you return an "ActionResult" object that indicates the result of the action method, and enables deferred execution of it. This allows much easier unit testing of actions (without requiring the need to mock anything). It also enables much cleaner composition and overall execution control flow. For example, we could use LINQ to SQL within our Browse action method to retrieve a sequence of Product objects from our database and indicate that we want to render a View of them. The code below will cause three pieces of "ViewData" to be passed to the view - "Title" and "CategoryName" string values, and a strongly typed sequence of products (passed as the ViewData.Model object): One advantage of using the above ActionResult approach is that it makes unit testing Controller actions really easy (no mocking required). Below is a unit test that verifies the behavior of our Browse action method above: We can then author a "Browse" ViewPage within the \Views\Products sub-directory to render a response using the ViewData populated by our Browse action: When we hit the /Products/Browse/Beverages URL we'll then get an HTML response like below (with the three usages of ViewData circled in red): Note that in addition to support a "ViewResult" response (for indicating that a View should be rendered), ASP.NET MVC Preview 3 also adds support for returning "JsonResult" (for AJAX JSON serialization scenarios), "ContentResult" (for streaming content without a View), as well as HttpRedirect and RedirectToAction/Route results. The overall ActionResult approach is extensible (allowing you to create your own result types), and overtime you'll see us add several more built-in result types. Improved HTML Helper Methods The HTML helper methods have been updated with ASP.NET MVC Preview 3. In addition to a bunch of bug fixes, they also include a number of nice usability improvements. Automatic Value Lookup With previous preview releases you needed to always explicitly pass in the value to render when calling the Html helpers. For example: to include a value within a <input type="text" value="some value"/> element you would write: The above code continues to work - although now you can also just write: The HTML helpers will now by default check both the ViewData dictionary and any Model object passed to the view for a ProductName key or property value to use. SelectList and MultiSelectList ViewModels New SelectList and MultiSelectList View-Model classes are now included that provide a cleaner way to populate HTML dropdowns and multi-select listboxes (and manage things like current selection, etc). One approach that can make form scenarios cleaner is to instantiate and setup these View-Model objects in a controller action, and then pass them in the ViewData dictionary to the View to format/render. For example, below I'm creating a SelectList view-model class over the | Go |
| May 20th Links: ASP.NET, ASP.NET AJAX, .NET, Visual Studio, Silverlight, WPF ... Apologies for the sparseness of my posting the last few weeks - work and life have been busy here lately. Below is a new post in my link-listing series to help kick things up a little. Also check out my ASP.NET Tips, Tricks and Tutorials page and Silverlight Tutorials page for links to popular articles I've done myself in the past. ASP.NET Bulk Inserting Data with the ListView Control : Matt Berseth continues his awesome posts with one that shows how to handle bulk-editing of data using the ASP.NET ListView control in .NET 3.5. Master-Detail with the GridView, DetailsView, and ModalPopup Controls : Another great post from Matt that describes how to cleanly handle a common data entry scenario. Creating Great Thumbnail Images in ASP.NET : A really nice blog post by a different Matt that details an approach that generates high quality (and small) thumbnail images. Warning the User when Caps-Lock is on : Scott Mitchell has a nice article that describes how to automatically detect and warn users in login pages when the caps-lock button is on. ASP.NET Perf Issue: Large numbers of application-restarts due to virus scanners : Tess Ferrandez has a great post that details a debug session to determine why an ASP.NET application was restarting frequently (causing performance slowdowns). The issue was a virus scanner that was causing files to be constantly updated. Make sure to check out the logging code you can add to your application to identify restart causes like this. ASP.NET AJAX ASP.NET AJAX Progress Bar Control : Matt Berseth has another great article that describes his new ASP.NET AJAX Progress Bar control. Faster Page Loading By Combining Multiple JavaScript files in Batch : Omar Al Zabir (founder of PageFlakes.com and author of the great Building a Web 2.0 Portal with ASP.NET 3.5 book) has a good article that describes the performance benefit of merging multiple JavaScript file downloads. Note that .NET 3.5 SP1 will include a new script combiner feature that helps make doing this even easier. Create ASP.NET AJAX Server Controls using the ScriptControl base class : Chris Pietschmann has a nice article that talks about how to build new ASP.NET AJAX server controls by deriving from the built-in ScriptControl base class. Inline Edit Box and Postback Ritalin Beta : Dave Ward and Mike Davis have created a new CodePlex project for their popular Inline Edit Box and PostBack Ritalin ASP.NET AJAX controls. .NET 7 Ways to Simplify your code with LINQ : Igor Ostrovsky has a great blog post that talks about new code techniques you can use to improve your code using .NET 3.5 and the new language and LINQ features in it. Visual LINQ Query Builder for LINQ to SQL : Mitsu Furuta has created a cool Visual Studio designer that allows you to graphically construct LINQ to SQL queries. Also make sure to download download the latest LINQPad utility - which is invaluable for learning LINQ and trying out LINQ queries. DataContracts without Attributes (POCO support): Aaron Skonnard has a good post that talks about a nice usability change with .NET 3.5 SP1 that allows you to serialize POCO (plain old objects) using the WCF serializers. Ukadc.Diagnostics : Josh Twist pointed me at a new CodePlex project he is working on that extends the System.Diagnostics features in .NET to include richer logging features (SQL trace support, email support, etc). Visual Studio 11 More VS Short Cuts you Should Know : A great post that talks about a bunch of useful shortcuts to print out and remember when using Visual Studio. Did you know you can show extension methods in the object browser?: Sara Ford continues her excellent "Did you know" series. I confess I didn't know this one. Silverlight 50 New Silverlight 2 Beta 1 Screencasts: Mike Taulty and Mike Ormond have put together 50 nice tutorial screen-casts that cover Silverlight 2 - all in their "spare time". Wow. AutoComplete for Silverlight TextBoxes : Nikhil Kothari has a | Go |
| Visual Studio 2008 and .NET Framework 3.5 Service Pack 1 Beta ... Earlier today we shipped a public beta of our upcoming .NET 3.5 SP1 and VS 2008 SP1 releases. These servicing updates provide a roll-up of bug fixes and performance improvements for issues reported since we released the products last November. They also contain a number of feature additions and enhancements that make building .NET applications better (see below for details on some of them).
We plan to ship the final release of both .NET 3.5 SP1 and VS 2008 SP1 this summer as free updates. You can download and install the beta here .
Important: SP1 Beta Installation Notes
The SP1 beta released today is still in beta form - so you should be careful about installing it on critical machines. There are a few important SP1 Beta installation notes to be aware of:
1) If you are running Windows Vista you should make sure you have Vista SP1 installed before trying to install .NET 3.5 SP1 Beta. There are some setup issues with .NET 3.5 SP1 when running on the Vista RTM release. These issues will be fixed for the final .NET 3.5 SP1 release - until then please make sure to have Vista SP1 installed before trying to install .NET 3.5 SP1 beta.
2) If you have installed the VS 2008 Tools for Silverlight 2 Beta1 package on your machine, you must uninstall it - as well as uninstall the KB949325 update for VS 2008 - before installing VS 2008 SP1 Beta (otherwise you will get a setup failure). You can find more details on the exact steps to follow here (note: you must uninstall two separate things). It is fine to have the Silverlight 2 runtime on your machine with .NET 3.5 SP1 - the component that needs to be uninstalled is the VS 2008 Tools for Silverlight 2 package. We will release an updated VS 2008 Tools for Silverlight package in a few weeks that works with the VS 2008 SP1 beta.
3) There is a change in behavior in the .NET 3.5 SP1 beta that causes a problem with the shipping versions of Expression Blend. This behavior change is being reverted for the final .NET 3.5 SP1 release, at which time all versions of Blend will have no problems running. Until then, you need to download this recently updated version of Blend 2.5 to work around this issue.
Important Update : If you previously installed a VS 2008 Hotfix, you must run the HotFix Cleanup Utility before installing the VS 2008 SP1 Beta. Click here to download and run this.
Improvements for Web Development
.NET 3.5 SP1 and VS 2008 SP1 contain a bunch of feature improvements targeted at web application development.
The VS Web Dev Tools team has more details (including specific bug fix details) on some of the VS specific work here . Below are more details on some of the work in the web-space:
ASP.NET Data Scaffolding Support (ASP.NET Dynamic Data)
.NET 3.5 SP1 adds support for a rich ASP.NET data "scaffolding" framework that enables you to quickly build functional data-driven web application. With the ASP.NET Dynamic Data feature you can automatically build web UI (with full CRUD - create, read, update, delete - support) against a variety of data object models (including LINQ to SQL, LINQ to Entities, REST Services, and any other ORM or object model with a dynamic data provider).
SP1 adds this new functionality to the existing GridView, ListView, DetailsView and FormView controls in ASP.NET, and enables smart validation and flexible data templating options. It also delivers new smart filtering server controls, as well as adds support for automatically traversing primary-key/foreign-key relationships and displaying friendly foreign key names - all of which saves you from having to write a ton of code.
You can learn more more about this feature from Scott Hanselman's videos and tutorials here .
ASP.NET Routing Engine (System.Web.Routing)
.NET 3.5 SP1 includes a flexible new URL routing engine that allows you to map incoming URLs to route handlers. It includes support for both parsing parameters from clean URLs (for example: /Products/Browse/Beverages), as well as supp | Go |
| Professional ASP.NET 3.5 Book (only $16 on Amazon for a short time) ... One of the things I like to track are book sales on Amazon.com, which provides a useful data point to monitor what developers are interested in on any given day. I use the www.TitleZ.com site (which is built using ASP.NET) to track specific titles I want to watch - it then generates a report showing real-time Amazon sales ranking data, as well as 7 day, 30 day and 90 day sales ranking averages. This morning I pulled up my report and saw the usual books near the top of my list, and was about to navigate away when I noticed the eye-popping amazon ranking of the top book -"Professional ASP.NET 3.5: In C# and VB " by Bill Evjen, Scott Hanselman and Devin Rader. Its Amazon sales rank was a stunning #95 (of all books on Amazon), which meant it was outselling even Harry Potter (which is pretty much unheard of for any technology book). It turns out that Amazon is holding a special price promotion for a short time on a few books - and this was one that was selected. Instead of the usual $54 price, you can buy it for a short time for a ridiculous $16.49. I'm not sure how long this promotion will last - but if you are looking for a great ASP.NET 3.5 book this might be something you might want to take advantage of: The book is a great ASP.NET 3.5 book and an excellent end to end resource. It has been on the best seller list for programming books since it came out in March (usually in the top 5 of all programming titles), and has received glowing reviews (I posted a review of it on Amazon a few weeks ago and gave it 5 stars). If you are in the market for a good ASP.NET book, you might want to consider taking Amazon up on this offer before it closes (and apologies in advance if the price changes before you read this). Hope this helps, Scott P.S. If you are looking for other good .NET 3.5 and VS 2008 books - I also recommend: C# 3.0 In a Nutshell , LINQ in Action , and Pro LINQ: Language Integrated Query in C# 2008 (all of which average a 5 star rating on Amazon). | Go |
| April 28th Links: ASP.NET, ASP.NET AJAX, ASP.NET MVC, Silverlight ... Here is the latest in my link-listing series . Also check out my ASP.NET Tips, Tricks and Tutorials page and Silverlight Tutorials page for links to popular articles I've done myself in the past. ASP.NET Displaying the Number of Active Users on an ASP.NET Site : Scott Mitchell continues his excellent series on ASP.NET's membership, roles, and profile support. In this article he discusses how to use ASP.NET's Membership features to estimate and display the number of active users currently visiting a site. ASP.NET Dynamic Data Update : The ASP.NET team last week released an update of the new ASP.NET Dynamic Data feature. This update adds several new features including cleaner URL support using the same URL routing feature that ASP.NET MVC uses, as well as better confirmation, foreign-key, and template support. ASP.NET Testing with Ivonna : Travis Illig blogs about a new testing framework named Ivonna that enables unit testing of ASP.NET web forms. ASP.NET AJAX ASP.NET AJAX UI Templates : Nikhil Kothari from the ASP.NET team has a cool post that shows off a prototype he has been working on that enables clean client-side AJAX templating of UI. ASP.NET AJAX Control Toolkit TabContainer Theme Gallery : Matt Berseth has another of his excellent posts - this one shows off a bunch of cool themes you can use to style the TabContainer control in the ASP.NET AJAX Control Toolkit. Reducing Page Load Times with UpdatePanels and Timers : Paul Glavich posts of a cool trick you can use with tab controls to asynchronously load their content in the background in order to improve perceived page load time. Why do ASP.NET AJAX page methods have to be static? Dave Ward has a useful article that talks about the page methods feature in ASP.NET AJAX, and explains why they are static methods. JQuery Intellisense in VS 2008 : Brad Vincent posts about using the VS 2008 Web Development Hot-Fix we released in February to get a nice JavaScript intellisense experience in Visual Studio 2008 when using the JQuery AJAX library. ASP.NET MVC Inversion of Control, ASP.NET MVC and Unit Testing : Fredrik Kalseth has a cool article that talks about the concepts behind inversion of control (IOC) and how you can use this with ASP.NET MVC to better isolate dependencies and enable better unit testing of your code. Stephen Walther's ASP.NET MVC Talk: Stephen Walther delivered a many-hour ASP.NET MVC post conference talk at ASP.NET Connections last week. You can download his slides + demos for free. Also check out his previous posts on Unit Tests with Visual Studio 2008 and TDD with Rhino Mocks . MVC Contrib Project Update : Eric Hexter blogs about some of the latest updates to the open source MvcContrib project to work with the latest ASP.NET MVC interim source release . Testing Action Results with ASP.NET MVC : Jeremy Skinner blogs about some cool extension method helpers he has added to MvcContrib to enable pretty sweet testing of Controller actions. MVC Membership Starter Kit - 1.2 Release : Troy Goode has posted an update to his excellent MVC Membership Starter Kit. This version works with the interim ASP.NET MVC source release. Silverlight Defining Silverlight DataGrid Columns at Runtime : Scott Morrison from the Silverlight team has a cool blog post that talks about how to define Silverlight DataGrid Columns via code at runtime. Visit my Silverlight links page for more DataGrid posts. Silverlight HTTP Networking Stack (Part 1 ), (Part 2 ), (Part 3 ): Karen Corby from the Silverlight team has a great three part blog series that talks about the new Silverlight 2 networking stack and how cross domain security works with it. Pushing Data to a Silverlight Client with Sockets (Part 1) and (Part 2) : Dan Wahlin demonstrates how to implement a "GameStream" socket server and connect to it from a Silverlight client using Silverlight 2's built-in network sockets support. Silverlight - the Song : Spike Xavier and Dan Wa | Go |
| Slides from my ASP.NET Connections Orlando Talks ... Last week I presented at the ASP.NET Connections Conference in Orlando. I gave a general session talk on Monday, and then two breakout talks later that day. You can download my slides+samples below: General Session The slides for my keynote can be downloaded here . In the talk I demonstrated how to debug the .NET Framework source code. You can learn how to set this up with VS 2008 here . I also demonstrated building a site using the new ASP.NET Dynamic Data support - which you can learn more about here . I also demonstrated using the new ASP.NET MVC Framework - which you can learn more about here . I also showed off the new Hard Rock Memorabilia site built with Silverlight 2. You can try out the Hard Rock application yourself here . You can learn more about Silverlight from my links page here . Building .NET Applications with Silverlight The slides + demos for Silverlight breakout talk can be downloaded here . You can learn more about Silverlight from my links page here . In particular, I recommend reading my tutorial posts here and here . ASP.NET MVC The slides + demos for my ASP.NET MVC talk can be downloaded here . You can learn more about the latest ASP.NET MVC source refresh here . Stephen Walther also just posted a really good set of slides + demos from his post conference tutorial on ASP.NET MVC here . Hope this helps, Scott | Go |
| ASP.net.com Community Links |
| Using jQuery with ASP.NET MVC ... The Microsoft ASP.NET MVC Framework has been getting talked about more and more lately. The power and flexibility of ASP.NET MVC allows for developers to use libraries other than those include in the box. The popular JavaScript framework, jQuery, is no exception. | Go |
| URL Rewriting in ASP.NET using URLRewriter.Net ... Learn to use search engine friendly URLs for your ASP.NET pages | Go |
| Using ASP.NET 3.5 History Control in ASP.NET 2.0 ... As ASP.NET 2.0 does not provide built in support for Back button functionality in AJAX Update Panel,
This post will show you how to use ASP.NET 3.5 Ajax ControlToolKit History control with ASP.NET 2.0, to achieve the back button functionality in ASP.NET 2.0 | Go |
| Using AJAX, LINQ and XML in C# ... AJAX and LINQ are two of the main focuses of Microsoft right now; and no wonder - both have huge potential and power behind them.
In this example, we will show how we can use AJAX coupled with LINQ and XML to create a Web Application that we can use to view stored data instantaneously, as well as add to it in the same way | Go |
| Forms Authentication in ASP.NET with C#: Advance ... This article describe how to create Roles based sccurity using Forms Authentication in easy to follow steps. | Go |
| MVC Preview 5 - Create Dynamic Action Links ... Explains how to add new views to sample project and create dynamic action links on the data coming from database ? Also explains how to use these dynamic actions links to perform database actions.
Sample Videos To Explains All these in action | Go |
| Handling Files and Directories from your web applications. ... Using C#, VB.NET, and ASP.NET to get all files of directory and subdirectory. Simply illustration of working with files and directories in ASP.NET. | Go |
| Programmatically Encrypt and Decrypt Configuration Sections in web.config using ASP.NET ... The ASP.NET Configuration API provides support for encrypting and decrypting configuration sections in web.config. This feature comes extremely handy when you need to hide sensitive information like passwords. In this article, we will explore how to encrypt and decrypt sections of the web.config. | Go |
| Role Based Content Rendering ... Designing a web based Information Management System poses a lot of challenges to developers. One of these challenges is how to provide desired level of security security to different users with different access to an application. You often encouter situations where certain users will be allowed to update specific fields while others can only view them. It is essential to design for adequate security features in the presentation layer of your application. | Go |
| Model Binders in ASP.NET MVC ... Hot off the presses, and new to ASP.NET MVC (Preview 5) is an awesome capability that (in my opinion) revolutionizes the way we design web applications. This feature is being touted (by me) as "the ViewState for MVC". | Go |
| CodeProject.com ASP Links |
| Web-Application Framework - Catharsis - part VII - Entity layer ... Catharsis web-app framework - Entity layer | Go |
| JavaScript Advanced List ... An advanced list that works with all objects | Go |
| Multi-lingual (Capable) Light Weight Report Writer with Drilldown ... Light Weight Report Writer with Drilldown, totalling and optional export to Excel | Go |
| Active Directory Roles Provider ... An active directory roles provider | Go |
| Writing Your Own RTF Converter ... An article on how to write a custom RTF parser and converter | Go |
| Adding footnotes to a word document programatically (MS Office 2007 word) ... This is an article about adding footnotes to a word document (MS Office 2007) programatically. | Go |
| Agile Development FAQ Part 1 ... Agile Development FAQ Part 1 | Go |
| Web-Application Framework - Catharsis - part VI - Framework Architecture ... Catharsis web-app framework - Framework Architecture | Go |
| Introduction to ASP.NET Dynamic Data Part - I ... An article on ASP.NET Dynamic Data | Go |
| Blend PDF with Silverlight ... Details & demo project of plumbing works that blend PDF and Silverlight visually with bi-directional data exchange. | Go |
| Color Picker ASP.NET AJAX Extender Control ... Web UI coclor picker control implemented as an ASP.NET AJAX Extender. | Go |
| Scheduling Future Dates ... Implement repetitive tasks at consistent intervals | Go |
| Web-Application Framework - Catharsis - part V. - adding new Entity ... Catharsis web-app framework - adding new Entity (enter into Catharsis) | Go |
| Nest Gridviews using LinqDataSource ... Here I will explain how to pur Gridview in other one , such as categories and products | Go |
| DotNetSlackers.com Links |
| Loading Web User Controls Dynamically in ASP.NET Pages ... Shows the correct way of loading and rendering web user controls dynamically in ASP.NET pages... Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here . | Go |
| The Big Problem of WYSIWYG Editors ... The Big Problem of WYSIWYG Editors and How to write a fast loading editor... Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here . | Go |
| Telerik RadControls in Microsoft ASP.NET MVC ... To continue with my previous blog post about RadGrid for ASP.NET AJAX in Microsoft ASP.NET MVC , I've made another example how to use RadControls for ASP.NET AJAX as pure client-side components in this environment. The biggest challenge here is the ScriptManager and scripts registration in general. By default the creation of client-side components is so tightly coupled with the ajax functionality (PageRequestManager) that the only way to enable this is to inherit from ScriptManager (or RadScriptManager) and build everything manually:
protected override void Render(HtmlTextWriter writer)
{
foreach (RegisteredScript script in GetRegisteredClientScriptBlocks())
{
if (Page.Items[script.Key] == null)
{
Page.Items[script.Key] = true;
if (script.ScriptType == RegisteredScriptType.ClientScriptInclude)
{
writer.WriteLine(String.Format(@"<script type="text/javascript" src="{0}"></script>", HttpUtility.HtmlEncode(script.Url)));
}
}
}
...
}
The result: Fully functional client-side enabled RadControls for ASP.NET AJAX with skins, scripts and styles combination, etc.!
Enjoy!
[Download ]
Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here . | Go |
| RadMenu for ASP.NET Ajax - Working with disabled JavaScript ... As you may know accessibility standards require a web page to work when JavaScript is disabled. In this blog post I will show you how to make RadMenu work even without JavaScript. I will also show how to make JAWS reader "see" all items rendered by RadMenu (even the hidden ones).
Disabling JavaScript
First we need to find a way to disable JavaScript in our browser of choice. For FireFox you need to install the web developer toolbar plugin . Then you can easily use the "Disable JavaScript" option:
In Internet Explorer you should first edit the security settings for the zone in which your test page is. Be careful to select the right zone - if you are testing locally you need to customize the "Local Intranet" zone:
Then set the "Active scripting" option to "Disable":
Making RadMenu open when JavaScript is disabled
By default RadMenu items open in response of the JavaScript mouseover event. This means that when JavaScript is disabled items won't open. Fortunately most modern browsers support the ":hover" pseudo CSS class on every HTML element. This allows the menu items to open only by using CSS:
< style type = "text/css" title = "RadMenu-Pure-Css" >
.RadMenu.rmItem:hover> .rmSlide,
.RadMenu.rmItem:hover> .rmSlide.rmGroup
{
display:block;
overflow:visible;
}
.RadMenu.rmItem:hover.rmSlide
{
top:100%;
left:0;
}
.RadMenu.rmItem.rmItem:hover.rmSlide
{
top:0;
left:100%;
}
.RadMenu.rmVertical.rmItem
{
float:none;
}
</ style >
Have in mind that animations will not work (remember that JavaScript is disabled). This CSS will affect the normal RadMenu behavior if JavaScript is enabled. To remove it we can use a few lines of JavaScript:
< body >
< script type = "text/javascript" >
//<!--
varstyles = document .getElementsByTagName("style");
for(vari = 0 ;i < styles.length ;i++)
{
if(styles[i].title =="RadMenu-Pure-Css")
{
styles[i].parentNode.removeChild(styles[i]);
break;
}
}
//-->
</ script >
That code will run only if JavaScript is enabled and remove the workaround stylesheet (based on its title).
What about older browsers which are still widely used?
Internet Explorer 6 supports the ":hover" pseudo CSS class only for "a" elements. This means that the aforementioned workaround will not work at all. What can we do about this? We can simply show all items to the user in case JavaScript is disabled. Here is the CSS:
< style type = "text/css" title = "RadMenu-Pure-Css" >
div.RadMenudiv.rmSlide,
div.RadMenuul.rmGroup,
div.RadMenuul.rmRootGroup
{
display:block;
overflow:visible;
position:static;
float:none;
}
div.RadMenuli.rmItem
{
float:none;
}
</ style >
Here is how the final result looks like:
Again you can hide it from browsers which have enabled JavaScript by using the code from the previous paragraph.
What about postbacks?
RadMenu is using JavaScript in order to postback when the user subscribes to the ItemClick event. When JavaScript is disabled the ItemClick event simply won't fire. Fortunately there is a workaround - using the ItemTemplate and controls which postback without JavaScript:
< telerik:RadMenu runat = "server" ID = "RadMenu1" Skin = "Hay" >
< ItemTemplate >
< asp:Button runat = "server" ID = "Button1"
CommandArgument = "<%#Container.UniqueID%>"
Text = "<%#Container.Text%>" OnCommand = "Button1_Command" />
</ ItemTemplate >
</ telerik:RadMenu >
The <asp:Button /> control does not require JavaScript in order to postback as it renders as <input type="submit" />. By assigning Comm | Go |
| Introduction to ASP.NET Dynamic Data Part - I ... An article on ASP.NET Dynamic Data... Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here . | Go |
| Review: Advanced ASP.NET AJAX Server Controls For .NET 3.5 ... This is a fine resource for ASP.NET developers who want to build high performance, data-driven Web applications with a richer user interface. The introduction of ASP.NET AJAX 2.0 extensions caught many of us off-guard. We were suddenly thrown into intensive...(read more)... Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here . | Go |
| ASP.NET Ajax simple image browser ... An article on showing an image browser in a web page using ASP.NET Ajax... Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here . | Go |
| Richmond Code Camp, Entity Framework and the Beer House ... I will be presenting an introduction to the Entity Framework and the Beer House this Saturday at the Richmond Code Camp . I have been very busy with the Beer House application, Entity Framework, ASP.NET AJAX, CSS Layouts and much more the past 2 months...(read more)... Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here . | Go |
| Color Picker ASP.NET AJAX Extender Control ... Web UI coclor picker control implemented as ASP.NET AJAX Extender... Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here . | Go |
| JQuery and ASP.NET MVC ... Where have I been? ;) You probably heard the news already form the GU already, but just in case, we will be shipping JQuerywith Visual Studio. ASP.NET MVC will have the privilege of being one of the first products to include JQuery. I am glad we finally announced this because I got tired of stifling my mouth everytime someone suggested we just include JQuery. :)
As you can see from demos I've done in the past, JQuery will fit nicely with the ASP.NET MVC style of development.... Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here . | Go |
| How To: Telerik RadGrid for ASP.NET AJAX with ASP.NET MVC ... I've made small example how to use RadGrid for ASP.NET AJAX in Microsoft ASP.NET MVC:
The key here is to inherit from RadGrid and call explicitly desired grid commands. Let's say you want to edit particular record:
1) Create a template column and add this to the ItemTemplate:
<%# Html.ActionLink("Edit", "RadGridCommand", new { ControlID = MyGrid1.ID, CommandName = "Edit", CommandArgument = Container.ItemIndexHierarchical }) %>
2) Now handle this in your controller:
public ActionResult RadGridCommand(string ControlID, string CommandName, string CommandArgument)
{
ViewData["ControlID"] = ControlID;
ViewData["CommandName"]= CommandName;
ViewData["CommandArgument"] = CommandArgument;
return View("Index");
}
3) Override OnPreRender in inherited class and call explicitly the grid RaisePostBackEvent() method:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (ViewData["ControlID"] != null && ViewData["ControlID"].ToString() == ID &&
ViewData["CommandName"] != null)
{
RaisePostBackEvent(String.Format("FireCommand:{0};{1};{2}", MasterTableView.UniqueID, (string)ViewData["CommandName"], (string)ViewData["CommandArgument"]));
}
}
For other useful techniques please refer to the attached source code.
Enjoy!
[Download ]
Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here . | Go |
| Visual Studio To Include jQuery Library ... In a tip of its hand toward open source software development, Microsoft announced on Sunday that it will incorporate the jQuery JavaScript library into Microsoft Visual Studio and ASP.NET.... Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here . | Go |
| MS + jQuery: This Is Huge! ... Yesterday, the ASP.NET team announced that they were going to ship jQuery, a small, populate open source web client library. And not only is Microsoft going to ship this library, as is, but we're going to build support into Visual Studio for it, build future versions of our web components assuming it and support it via PSS like any other Microsoft product.
This is huge.
Of course, is it useful for developers using Microsoft tools, because they get another supported library out of the box for them... Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here . | Go |
| Microsoft announces jQuery support in ASP.NET Ajax ... I just noticed a very interesting announcement by Scott Guthrie. Microsoft will officially start co-operating with jQuery development community, adding support for jquery in ASP.NET Ajax, and which also includes Microsoft PSS e.g they take support cases. Read more here . Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it! Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here . | Go |
| ASP.NET.com Links |
| Create ASP.NET MVC Controllers under Namespace and specific URL ... When you have a lot of controllers, you need to organize them under Namespaces. Also, it is better to put controllers under subfolders in order to organize them properly and have some meaningful URL for them like /Admin/User where Admin is the subfolder and User is the controller. For example, you might have a lot of controllers that are APIs exposed by your web app, not regular pages. So, you might want to put them under /API/ folder. You also want to make sure no one can access those controllers from the root url. For example, no one must call /User/GetUserList instead they must call /API/User/GetUserList ASP.NET MVC default routing and Controller Factory is very greedy, it ignores the subfolders inside the "Controllers" folder. There's a DefaultControllerFactory class in ASP.NET MVC which traverses all controllers under the "Controller" folder and creates a cache using just the class name as the key. So, it ignores any namespace or any subfolder where you have put the controller. So, I created a derivative of the default controller factory and created a new factory that checks if the requested controller belongs to any specific namespace and whether that controller must be inside a specific subfolder. You can map /Admin folder to respond to all controllers that are under then YourWebApp.Admin namespace. Similarly, you can map /API folder to respond to all controllers that are under the YourWebApp.API namespace. None of these controllers can be accessed outside the specified URL. Here's the factory that does it: This controller checks the namespace of the controller being returned by ASP.NET MVC's default implementation and ensures the requested URL is the right url where controllers from the namespace can be accessed. So, this means if the controller matches MvcWebAPI.API.UserController , it ensures the URL being requested must be /MvcWebAPI/API/User . It will return null if the URL was something else like /MvcWebAPI/User or /MvcWebAPI/SomeotherFolder/User . Here's how you use it form Global.asax : You create a mapping for a Namespace and the subfolder it must belong to. Then you register the new Controller Factory as the default controller factory. Now the second catch is, the default Route for the {controller}/{action}/{id} won't work for you. You need to create a specific router that starts with the subfolder name. For example, API/{controller}/{action} Here' two things to notice: The use of PathStartWith routing constraint, which I will explain soon The last parameter which tells the route to include the API namespace for this route. Otherwise it can't find the controllers in the API namespace So, the PathStartsWith routing constraint ensures this route gets hit only when the requested URL is under the /API/ folder. For any other URL, it returns false and thus the routing handler skips this route. It just does a comparison on the AbsolutePath of the current request URL to ensure the URL starts with the specified match. Similarly, we need to tell the Default route to ignore all paths with /API . Here's how to do it: That's it. Enjoy the full code from: http://code.msdn.microsoft.com/MvcWebAPI Read my previous post on creating Web API using ASP.NET MVC that can consume and expose Json and Xml: Create REST API using ASP.NET MVC that speaks both Json and plain Xml Note: incase you already read it, I have published new code that you should download. | Go |
| ASP.NET 3.5 FREE Hosting....!! ... Good morning, Want to test your web applications on live with free hosting. Try this one : Link It is supporting ASP.NET 3.5 and SQL Server 2005. Enjoy, Krunal | Go |
| Enumerations And Extension Methods ... Enumerations are for enumeration. Obvious. Often, though, it's used also for some metadata knowledge. For example, an enumeration for gender might look like: public enum Gender
{
Male,
Female
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; } Two options, simple. Now let's say I want to populate a drop down list with these values and some meta data. It's simple when it's English (a proper enumeration value would mostly match the metadata, but not always), what about another language? Normally I would build a workaround this, to have a utility class that would get a gender value and based on it return the metadata for the required culture. Does the work, but leaves bad taste after.
This is where extension methods can make it nicer. I will not go for the cultures, but capital and lower cases, but culture solution should not be that different.
Gender is closed for changes, but we need to be able to 'extend' it's functionality without 're-opening' it. The next code snippet shows how to achieve the required functionality:
public static class GenderExtensions
{
public static string ToNiceName(this Gender gender,
IGenderFormattingStrategy formattingStrategy)
{
return formattingStrategy.ToStringWithFormatting(gender);
}
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
In this case I used a strategy pattern for formatting. What is nice, is that now we can test the extension method, knowing that Gender is not something we should be testing at all, but the result of ToNiceName() method.
1: [Concern(typeof (GenderExtensions))]
2: [TestFixture]
3: public class when_converting_gender_to_string_with_strategy
4: : SpecificationContext<Gender>
5: {
6: private string resultMaleCapitalized;
7: private string resultMaleLowered;
8: private IGenderFormattingStrategy capitalizedStrategy;
9: private IGenderFormattingStrategy loweredStrategy;
10:
11: protected override Gender EstablishContext()
12: {
13: capitalizedStrategy = Stub<IGenderFormattingStrategy>();
14: loweredStrategy = Stub<IGenderFormattingStrategy>();
15:
16: capitalizedStrategy.Expect(
17: strategy => strategy.ToStringWithFormatting(Gender.Male))
18: .Return("MALE" );
19: loweredStrategy.Expect(
20: strategy => strategy.ToStringWithFormatting(Gender.Male))
21: .Return("male" );
22:
23: return Gender.Male;
24: }
25:
26: protected override void BecauseOf()
27: {
28: resultMaleCapitalized = sut.ToNiceName(capitalizedStrategy);
29: resultMaleLowered = sut.ToNiceName(loweredStrategy);
30: }
31:
32: [Test]
3 | Go |
| Agile Testing tools List ... Working on an appendix for my book , with a list of tools and frameworks you should care about. Tell me if I missed anything: · Mock Frameworks o Moq o Rhino Mocks o Typemock Isolator o NMock o NUnit.Mocks · Test Frameworks o MS Test o NUnit o MbUnit o XUnit o Gallio · Dependency Injection and Ioc Containers o StructureMap o Microsoft Unity o Castle Windsor o Common IServiceLocator Framework o Managed Extensibility Framework o Spring.NET o AutoFac · Database testing o Use Integration testing o MbUnit,NUnit,XUnit Rollback attributes o TransactionScope · Web Testing o Ivonna and Typemock o Team System Web Test o NUnitASP o Watin o Watir o Selenium · UI Testing o NUnitForms o Project White o Team System UI Tests o Typemock Isolator · Threading Related Testing o Microsoft Chess o Typemock Racer o Osherove.ThreadTester · General Testing o Pex · Acceptance Testing o Fit & Fitnesse o Watin and Watir and selenium | Go |
| Assembly Reference for Visual Studio 2005 / 2008 ... You will always have trouble to reference you right assembly or track the right assembly.Here is on nice tool help you found for visual studio .net http://www.codeproject.com/KB/macros/Lexware.AssemblyReference.aspx Thanks, Suresh Behera | Go |
| Another Standard Deviation Extension for LINQ ... Just wanted to post my SDev extension for linq
HopeFully someone will find it helpfull
Happy coding all
DK Module Module1
<Runtime.CompilerServices.Extension()> _ Function StDev( Of T)( ByVal Values As System.Collections.Generic.IEnumerable( Of T), ByVal selector As Func( Of T, Double ))
Return Statistics.StDev(Values.Select(selector).ToList()) End Function
End Module Public Class Statistics
Public Shared Function StDev( ByVal Values As System.Collections.Generic.List( Of Double )) Dim n = Values.Count()
Dim SigXSquare = ( From i In Values Select i * i).Sum() Dim SigX = Values.Sum()
Dim SigSquareX = SigX * SigX Dim MySTDev As Double = ((n * SigXSquare) - SigSquareX) / (n * (n - 1))
Dim root = Math.Sqrt(MySTDev) Return root End Function
End Class | Go |
| Debugging ASP.NET MVC Routing ... One of the most critical pieces to MVC is routing users to the proper controller. During the development process, you must keep in mind that routes will take users to the first pattern that matches. It’s not that difficult to create patterns that are too similar that users are routed to the incorrect place. Phil Haack, from the ASP.NET team, has created a cool library to help routes. You can download his library at http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx . When you download the library, be sure to place it in your bin directory and add a reference to it within your project. He’s updated it for MVC Preview 5. | Go |
| Create REST API using ASP.NET MVC that speaks both Json and plain Xml ... ASP.NET MVC Controllers can directly return objects and collections, without rendering a view, which makes it quite appealing for creating REST like API. The nice extensionless Url provided by MVC makes it handy to build REST services, which means you can create APIs with smart Url like "something.com/API/User/GetUserList" There are some challenges to solve in order to expose REST API: Based on who is calling your API, you need to be able to speak both Json and plain old Xml (POX). If the call comes from an AJAX front-end, you need to return objects serialized as Json. If it's coming from some other client, say a PHP website, you need to return plain Xml. Similarly you need to be able to understand REST, Json and plain Xml calls. Someone can hit you using REST url, someone can post a Json payload or someone can post Xml payload. I have created an ObjectResult class which takes an object and generates Xml or Json output automatically looking at the Content-Type header of HttpRequest . AJAX calls send Content-Type=application/json . So, it generates Json as response in that case, but when Content-Type is something else, it does simple Xml Serialzation. Here's the ObjectResult that you can use from Controllers to return objects and it takes care of proper serialization method. Above shows the Json serialization, which is quite simple. XmlSerialization is a bit complex though: Things to note here: You have to force UTF8 encoding. Otherwise it produces UTF16 output. XML Declaration is skipped because that's not quite necessary. Wastes bandwidth. If you need it, turn it on. I have turned on indenting for better readability. You can turn it off to save bandwidth. Some of you might be boiling inside looking at my obscure coding style. I love this style! I am spoiled by jQuery. I wish there was a cQuery. I actually started writing one, but it never saw day light just like my hundred other open source attempts. Now back to Object Serialization, we got the serialization done. Now you can return objects from Controller easily: You can use the test web project to call these methods and see the result: So far you have seen simple object and list serialization. A best practice is to return a common result object that has some status, message and then the real payload. It's handy when you only need to return some error but no object or list. I use a common Result object that has three properties - ErrorCode (0 by default means success), Message (a string data type) and Data which is the real object. When you want to return only a result with error message, you can do this: This produces a result like this: No payload here. So, the return format is always consistent. Those who are consuming service can write a common Xml or Json parsing code to consume both success and failure response. Those who are building API for their website, I humbly request you to return consistent response for both success and failure. It makes our life so easier. So, far we have only returned objects and lists. Now we need to accept Json and Xml payload, delivered via HTTP POST. Sometimes your client might want to upload a collection of objects in one shot for batch processing. So, they can upload objects using either Json or Xml format. There's no native support in ASP.NET MVC to automatically parse posted Json or Xml and automatically map to Action parameters. So, I wrote a filter that does it. This filter intercepts calls going to Action methods and checks whether client has posted Xml or Json. Based on what has been posted, it uses DataContractJsonSerializer or simple XmlSerializer to convert the payload to objects or collections. You use this attribute on Action methods like this: The attribute expects a parameter name where it stores the deserialized object/collection. It also expects a root type that it needs to pass to the deserializer. If you are expecting a single object, specify typeof(SingeObject) . If you are expecting a list of objects, specify an array | Go |
| Guidance Automation Extensions for VS2008 SP1 is available. ... Today we've release the Guidance Automation Extensions - February 2008 Release SP1 , which addresses the following issues: Registering and Using Guidance Packages on the Visual Studio Experimental Hive Registering and/or using a guidance package in the Visual Studio Experimental hive fails when Visual Studio 2008 Service Pack 1 is installed. This is now fixed. Regular Expression Evaluation Enhancements When an operation (or a message) was created, the duration of the creation task was directly proportional...(read more ) | Go |
| New REST "must read" papers ... Normal 0 false false false EN-US X-NONE X-NONE /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",...(read more ) | Go |