Random ASP.NET Tips and Tutorials

Posted by: Suprotim Agarwal , on 8/4/2011, in Category ASP.NET
Views: 137323
Abstract: Here are some random ASP.NET tips and tutorials you will find useful

Lately I have been compiling some tutorials on Silverlight, SharePoint and LINQ and I am glad to receive good feedback on the same. Here are the links in case you missed them

Microsoft Silverlight 4 Tutorials You Must Read 

50 LINQ Examples, Tips and How To's

SharePoint 2010 Tutorials For Beginners and Intermediate Developers 

Continuing the link list series, here are some random ASP.NET tips and tutorials I wrote on my blog. Hope you like this list too! My goal is to add new posts to this series going forward – so bookmark this page for updates and please retweet this link to share these tips with fellow developers.

If you are an ASP.NET MVC developer, make sure you check our ASP.NET MVC tutorials over here.

 

Random ASP.NET Tips and Tutorials

Test Emails in ASP.NET without a Mail Server - The tip I am going to share today is an old one but many developers do not know about it. Assume you are creating an application and need to test a module that sends out bulk mails, like a newsletter. Your first thought would be to configure an SMTP server to test the email module. However there is a trick that you can make use of while testing your code.

jQuery: Highlight Source Code in HTML and ASP.NET Pages - I recently stumbled upon the Snippet plugin which is a syntax highlighting plugin and provides a quick and easy way of highlighting source code passages in HTML documents. I needed a similar implementation for displaying source code (with syntax highlighting and copy), while generating some documentation for a product. Let us see how to implement this plugin in an ASP.NET page.

Avoid DataBinder.Eval in ASP.NET and improve Performance - I see a lot of developers using DataBinder.Eval, which evaluates data-binding expressions at run time. Although the DataBinder.Eval is quite frequently used in web controls like the GridView, Repeater etc, use it with caution.

ASP.NET 4: Register HTTP Module at Runtime without Editing your Web.config - Not known to many developers, ASP.NET 4.0 provides the PreApplicationStartMethodAttribute which allows you to run code even before any app_start event gets fired or any dynamic compilation occurs (App_code). This allows use to register modules without touching your web.config

ASP.NET 4 Granular View State - In this post, we will see how to control a view state at Page level as well as Control level. In ASP.NET 4.0, Microsoft has provided a property called 'ViewStateMode' at control level. Now you can turn OFF the View state at Page level and turn ON viewstate at Control level as per your requirements.

Call ASP.NET Handler (ASHX) using JavaScript - I was working on an application which used AJAX and needed the XMLHttpRequest object to communicate with an ASP.NET Generic Handler (.ashx), which contained some server-side logic. Here’s a working prototype if you have a similar requirement

Remove X-AspNet-Version and X-Powered-By HTTP Header using IIS - When an HTTP request is made to a web server (like IIS), HTTP headers are transferred from the Browser to the webserver and vice-versa. The HTTP Headers sent by IIS to the browser gives information like how to render the content or gives information about the web server software, version etc. One such HTTP Headers is the X-Powered-By and X-AspNet-Version which tells the browser that the site is powered by ASP.NET and the ASP.NET version that is used by the web server

Render Dynamic MetaTags in ASP.NET Page in Separate Lines - In ASP.NET using code with the HTMLMeta class, we can define the HTML meta elements on an ASP.NET page. But the output is all mixed in one line. Can i separate it ? This post shows how to do so.

Call JavaScript from an ASP.NET AJAX Update Panel in Content Page Load - While calling a JavaScript function from a Content Page Load method, you can use the ClientScript.RegisterStartupScript method. However the same does not work if the content page is wrapped inside an ASP.NET AJAX Update Panel. This post shows how to resolve this.

Bind to Multiple ASP.NET Site Map files - You can use more than one sitemap file and decide which one to bind to a control. This post shows how to bind a control like the Menu Control, to multiple ASP.NET Site Map files.

ASP.NET: SQLDataSource QueryString Handling - I have seen a lot of developers using the QueryStringParameter with the SQLDataSource for demo ASP.NET applications. A frequently asked question is how to perform checks in cases where the parameter has the value null or Nothing and supply a default value to it.

Register Script into Page Header from ASP.NET Content Page - We used the ‘RegisterClientScriptInclude’ to register script from a Content Page. However this approach adds the JavaScript reference inside the <body> tag of the page and not the <head>. A reader Simone mailed me asking if it was possible to use the same method to register the script into <head> portion of the page.

Remove ViewState from an ASP.NET Page - In this post, we will explore how to remove ViewState from your asp.net page and instead store it in a session. This could be useful when pages are to be served to devices with less resources.

Compress Session State in ASP.NET 4 - ASP.NET 4 introduces a new option called ‘compressionEnabled’ to compress session state and improve application performance.

Auto Generate Row Number in ASP.NET ListView - Is it possible to create a counter field or an auto-generated Row Number in an ASP.NET ListView? The solution is to add <%# Container.DataItemIndex + 1 %> to the ItemTemplate of the ListView as shown in this post.

Using the Deployment retail=true attribute - ASP.NET Settings - One of the most common errors while deploying ASP.NET websites into a production environment is to leave the Trace and Debug enabled or leave the custom errors attribute disabled. If you are a web administrator and have several websites deployed on your server, then here’s a simple tip to override these deployment mistakes

Give a +1 to this article if you think it was well written. Thanks!
Recommended Articles
Suprotim Agarwal, ASP.NET Architecture MVP, MCSD, MCAD, MCDBA, MCSE, is the CEO of A2Z Knowledge Visuals Pvt. He primarily works as an Architect Consultant and provides consultancy on how to design and develop .NET centric database solutions.

Suprotim is the founder and primary contributor to DotNetCurry, DNC .NET Magazine, SQLServerCurry and DevCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls. and is authoring another one at The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal


Page copy protected against web site content infringement by Copyscape


User Feedback
Comment posted by Anand R on Monday, November 7, 2011 10:50 AM
Good Article .... Useful one !! thank you !!
Comment posted by salman ansari on Friday, June 1, 2012 6:06 AM
nice article i have read your 51 Recipe ebook its also very nice for everyone which wants to envolve his hands in Jquery
Comment posted by Suprotim Agarwal on Sunday, June 3, 2012 1:41 AM
@Anand You are welcome :)

@Salman Thanks for the kind words :)
Comment posted by dave4616 on Thursday, June 7, 2012 4:52 AM
Wow! really useful article! ;) I’m a student learning ASP and I have a project to develop some VoIP applications. I would like to use sample programs by Ozeki VoIP SIP SDK because they have trial version for free.
Have you tried/used these sample programs? For example this one: http://www.voip-sip-sdk.com/p_203-asp-net-sip-voip-client-voip.html
If yes, could you please give me a review of it?
Thanks for your time in advance!
Regards,

Dave Keller
Comment posted by dave4616 on Thursday, June 7, 2012 4:53 AM
oh and sorry for double posting! my bad!

Post your comment
Name:  
E-mail: (Will not be displayed)
Comment:
Insert Cancel