Wednesday, May 22, 2013

Replace line breaks in C#

In recent days I was working on a project want to replace \r\n to a new character but it was giving very strange behaviour. It was not replacing proper. Let’s create that scenario. I have written following code.
using System;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string sample = @"This is string for replacing new
                                 line \r\n This may not work";
            Response.Write(sample.Replace(@"\r\n",@"<br />"));
        }
    }
}

If you see the above code looks like it should work fine. But when you run this in browser in some environment it working fine and in some environment it was not working fine. Just like below.

Share:
Friday, May 17, 2013

Visual Studio 2012 Tip- Closed All But Pinned feature

Visual studio 2012 is one of best IDE I have ever used. Everyday I am discovering something new with that IDE which is more productive. Today I have discovered “Closed All But Pinned” feature. I thought It’s a good idea to write a quick tip post.

Problem with Earlier Version:


Earlier we used to have “Close All But This” feature from Visual Studio 2008 which will close all the files except the that file. But what we should do If we need to have more than one file opened. There was not way for it in Visual Studio 2008.

So if we have requirement like above situation where we need to kept open more than one file. This features comes quite handy. You just have to pin files that you want it to be opened.

PinnedFile in Visual Studio 2012

Share:
Monday, May 6, 2013

Unobtrusive validations in ASP.Net 4.5 Web Forms

With the release of ASP.Net 4.5 web forms there are tons of features added in the ASP.Net and Unobtrusive validations support is one of them. We have already seen that kind of validation in ASP.Net MVC and now we are going to have that in ASP.Net web forms. In this post I am going to explain how its works and how its different from earlier versions.

How validation was working with earlier versions?


In the earlier versions of ASP.Net it was working via putting a JavaScript for that. Let’s take a simple example. I have putted three things here. A textbox, required field validator and a button like following.

Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews