Tagged: code snippet

0

Some useful UpdatePanel extensions

I want to share some pretty basic and useful UpdatePanel control extensions with you. Method names are self explaining so I will not go deep in details. public static void AlertOnLoad(this UpdatePanel updatePanel, string key, string message) { message = message.Replace(“‘”, “\'”).Replace(“\r\n”, “”).Replace(“\n”, “”); message = “alert(‘” + message + “‘);”; AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript(updatePanel, updatePanel.GetType(), key, message, true); } public static void...

0

How to generate RSS feeds without any 3rd party components

RSS feeds are widely used in today’s internet world. Thus we, developers, have to implement it on our websites and projects most of the time. There are many free and paid components that generates RSS feeds but in fact you may generate it by yourself as well. I will post a generic handler’s source code to show you how to...

2

Easiest way of global error handling in an ASP.NET application

Since there are different ways of global error handling in ASP.NET applications and you have to implement the one that best fits into your project’s architecture, I will not be discussing all the possibilities that ASP.NET provides you. However, I will just share a small code snippet that you can use to catch unhandled exceptions and write a small piece...

3

Strip all HTML tags from string

This is something we need very often. Either for security reasons or just because of some business rules. I will share a small code snippet with you as an extension method to string type so you can take advantages of using Regular Expressions to remove HTML tags from any user input. public static string StripHtml(this string value) { if (string.IsNullOrEmpty(value))...

0

How to uppercase the first letter of a word or sentence

When I used to use PHP to develop my web applications, I really loved its basic but useful method named ucfirst. This function is explained using a simple explanation on PHP documentation: ucfirst — Make a string’s first character uppercase I believe within all those useful and complex libraries taking place in .NET Framework, it still misses these kind of...