Making AjaxRequest Calls From UserControls and Content Pages
|
I think this is a fairly common scenario. You have a master page (or several), user controls and content pages in your asp.net application. You also use the Telerik RadControls for additional functionality on your web pages, and you want to use the excellent, built-in Ajax functionality in the RadControls.
I recently implemented a tab strip with a context sensitive menu, i.e., right click on any tab strip to get a context menu. A click on any on the context menu's items will make an Ajax call to the user controls code behind .cs file. The problem I ran into was that the tab strip is implemented in a user control - and thus the context menu must also be in the same user control. The user control must then have a RadAjaxManager definition on the page. However, I also have other Ajax stuff going on in my system, and therefore ran into a problem when it comes to handling OnAjaxRequests and the use of RadAjaxManagerProxy (because the proxy does not expose the OnAjaxRequest function). Here I will explain how you - with a few, simple lines of code - can solve this problem.
|
Payment Solution using PayPal Express Checkout SOAP API
|
I've just implemented a payment solution using PayPal Express Checkout with the SOAP API. Since PayPal - and especially the SOAP API - is not trivial, I thought I would share some of the implementation details with you.
I, like every other developer out there, started out by going to the PayPal site - paypal.com. You then click the "Business" tab and select the "Products & Services" link. Well, what will you find - not more than 6 different web-site payment solutions. There is a lot of documentation and information about each PayPal offering, and in addition you have the PayPal X Developer Network - https://www.x.com/index.jspa. The documentation is great - but totally overwhelming :( So if you really want to learn how to use PayPal, it is probably better to go and buy one of the many great books that are out there - or you could just read on...
|
Converting to Search Engine (SEO) Friendly ASP.NET 4.0 Routing
|
I've been working on implementing routing in asp.net 4.0 forms for the last couple of days. The way the guys at Microsoft implemented this is actually really nice. So to make my CMS - PrimePublish - more SEO friendly, I decided to convert it to asp.net 4.0, and specifically implement the new SEO features that this version has to offer.
In this blogpost, I will describe some of the issues that I was faced with when converting. These are typically related to Javascript, CSS (Stylesheet), AJAX calls, and so on. It actually took me a long time to figure out all the small things that all of the sudden did not work after I implemented routing. This blogpost attempts to give you a list of the most common issues, and I also try to explain some workarounds that I implemented.
If you are just starting out with asp.net 4.0 and want to implement routing, then you should start out by reading Scott Guthrie's blog from october 2009. Scott gives here a simplied, but very good explanation of the asp.net 4.0 routing features.
|
Pop-up Menus Hidden Behind Flash Content
|
Here is a solution to a fairly commen problem - why does pop-up menus get hidden behind Flash content and not other images or content. Setting the Z-index to a high value does not have any effect either. Well, there is a simple solution to this problem, and it is done by a setting a couple of parameters in your Flash markup. Here is the markup that you need to include:
<object width="600" height="400" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
<param name="Movie" value="/uploads/NC_2010_USA_home2.swf"/>
<param name="play" value="true"/>
<param name="quality" value="high"/>
<param name="wmode" value="transparent"/>
<param name="loop" value="false"/>
<param name="menu" value="false"/><embed src="/uploads/NC_2010_USA_home2.swf" width="600" height="400" type="application/x-shockwave-flash" pluginspage=" http://www.macromedia.com/go/getflashplayer" quality="high" wmode="transparent" loop="false" menu="false"></object>
Make sure to indclude the markeup in yellow and you should be all set.
André
|
Session timeout, how to avoid timeouts as long as user is on site
|
How many times have you pushed the "Save" button just to realize that your session had timed out and you lost everything. Pretty annoying, isn't it? Well, in my CMS system - PrimePublish - I had to come up with a good solution for this, and I set out searching the web for a solution. There are actually a lot of solutions out there, but most of them rely on JavaScript or some counters, or some other clever mechanism. Not that these solutions wouldn't work, but I wasn't quite happy with the solutions I found, so the search continued. Finally I found a pretty clever solution - a solution that requires only two lines of code, and at the same time ensuring that the session will not time out. Also, it does not use JavaScript.
|
Regular Expressions (RegEx), cheat sheets and examples
|
Are you like me and tend to forget the regex-expressions between each project. Well, I just had to revisit the usage of regex, and came accross these cheat sheets on the web. They came in pretty handy for me, and I therefore thought that I should post them here for later reference.
I have also posted a few examples that might come in handy for you. I even posted a snippet that will find any HTML tag and its closing tag - a pretty cool regex-expression!
|
Search Engine Optimization, 301 Moved Permanently
|
Ever wondered how to automatically redirect from one URL to another - and to do this without getting penalized by the search engine. Well, it's pretty easy - read on for an explanation and code example...
First of all, always use the "301 Moved Permanently" feature to redirect a page from the old location to the new. Otherwise, you may experience a huge downward leap in search engine rankings, 302 hijacking penalties, or other penalties from the search engine. Do not use JavaScript or client-side redirects as these often will be misinterpreted by search engines and cause penalties.
The most common use for the 301 redirect, which all site owners need these days, is the redirect from the "non-www" version of the site's URL to the "www" one (for example, http://mydomain.com/ to http://www.mydomain.com/). This helps prevent the 302 hijacking.
Insert the code below into your Global.asax, and you are all set :)
|
Session variables versus ViewState
|
Every now and then programmers will get these confusing error messages that can take hours to figure out. I recently ran into one like this. After having implemented a few changes in my program, the program would crash with an error message like:
Type 'SomeNamespace.Web.Data.ProviderDataSourceDeepLoadList' in Assembly
'SomeNamespace.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
is not marked as serializable
I eventually tried to Google (actually I typically use Bing) the error message without much luck. There were very little information on the net about this particular error message, and I therefore had to figure this one out on my own.
I eventually found the solution to the problem. The thing was that I had replaced a session variable with a variable stored in ViewState. Switching the variable to a Session variable solved the problem and the error disappeared.
Happy debugging :)
|
Localizing JavaScript variables
|
Ever made a localized web site? Well, ASP.net has excellent support for this using local and global resource files. However, a project typically also involves JavaScript functions - often using the "alert" feature to give feedback to the user.
|
IE Conditional Comments in CSS
|
The concept of Conditional Comments was introduced with the release of Internet Explorer 5. It makes it possible for the developer to detect IE browser versions, and thus give the developer an option to load style sheets based on the version information. This way, your application can take full advantage of the advanced features found in newer browsers, while also writing pages that downgrade gracefully in less-capable browsers or display correctly in browsers other than IE.
Conditional comments should be placed in the <head> section of your pages (or Master page) and has the following syntax:
<!--[if lt IE 8]>
<link href="CSS/StylesheetIElt8.css" type="text/css" rel="stylesheet" media="Screen" />
<link href="CSS/StylesheetMenuIElt8.css" type="text/css" rel="Stylesheet" media="screen" />
<![endif]-->
Make sure you load your general stylesheets before the conditional comment to adhere to the cascading rules of CSS.
Conditional comments come if a variety of flavors like:
<!--[if IE]>...<![endif]--> //If Internet Explorer
<!--[if lt IE 8]>...<![endif]--> //if less than Internet Explorer version 8
<!--[if lte IE 7]>...<![endif]--> //if less than or equal Internet Explorer version 7
<!--[if (IE 6)|(IE 7)]>...<![endif]--> //the OR operator
Conditional comments are Microsoft's preferred means of differentiating Cascading Style Sheets (CSS) rules intended for specific versions of Internet Explorer.
NB! If you are using Telerik's RadControls, then be aware that RadAjax does not interpret the IE conditional comments correctly, i.e., <!--[if lt IE 8]>...<![endif]-->. One simple fix to this problem is to set the EnablePageHeadUpdate property of the ajax control to false. You may read more about this on the Telerik Watch blog.
|
CSS, what about those old tables
|
Are you like me and have finally managed to figure out the "new" stylesheet standards. That is the system for absolute and relative positioning, left and right float, and so on. Well, you are in for a treat...
Traditional CSS is pretty much designed to display a vertical stack of blocks, piled one on top of another - each containing either another stack of blocks, or text wrapped to fit inside the block. This system has its obvious limitations, and is the reason to why a lot of web designers still use the old HTML table tag when designing web pages.
Tables have actually been part of the CSS spesification since CSS 2.1, but the problem has been that the browsers - specifically Internet Explorer - did not support this specification until the release of IE8.
After the release of IE6, and its established dominance in the market, Microsoft decided (silently) to scale down - or even stop - its browser development and moved its programmers on to other projects. While other browser companies continued to improve their browsers, Microsoft's browser simply hibernated. However, based on Firefox's growing popularity, Microsoft eventually decided to get back into the race and develop new versions of IE. On October 18 2007, IE7 (six years after IE6!) was introduced, however without support for some crucial CSS2.1 support like table layout.
With the introduction of IE8, Microsoft is definitely back in the browser market. IE8 has full support for the CSS2.1 specification. And now the race is on for implementing CSS3.0...
You may read more about CSS tables on http://www.w3.org/TR/CSS2/tables.html.
|
|
Ever tried to perform nested joins in SQL. It can get pretty messy after a few joins...
On a previous project I had to join five tables with a combination of inner and outer joins. Click on the "Read more..." link to see the code I used in a my project.
|
Uploading and downloading files with AJAX
|
AJAX is a great technology as it enables the designer to make responsive user interfaces by avoiding loading unnecessary information whenever an update is required. I, therefore, use AJAX extensively in my projects, and it normally works great.
On a recent project I ran into a problem though. I Ajax-enabled a GridView and a FormView, but the problem arised when trying to download files from those controls. Uploading or downloading files does not work in AJAX. This is a limitation of the XmlHttpRequest component, used in all AJAX frameworks for asynchronous calls to the application. You must therefore force a full postback in order to upload or download files.
|