Objects in this mirror are closer to Microsoft Technologies. DNM objective is to help users on Microsoft technologies by providing Articles, snippets, Interview Questions.

02 September 2012

Change the text of a span control in javascript


In this tip we will see how to change the text of span control using Javascript. In HTML/ASPX page, span control will be defined as 
<span id="spanElement"> span text </span> 

In order to change the value of span element in java script use below code. 
document.getElementById('spanElement').innerHTML = "span text from JS";


31 August 2012

Remove special characters (!@#$%.etc) with empty string from a string using JavaScript


Using java script if you want to remove special characters from a string, we can achieve using regular expression.

The below code will allow alphabets (lower and upper case) and numbers in a string.
var str = '@This is sample sting from <.NET Mirror> Ready! 1#2%3*Go';
var rStr = str.replace(/[^a-zA-Z0-9]+/g, '');
alert(rStr);
Output : ThisissamplestingfromNETMirrorReady123Go

If you want allow some of special characters then add them to expression. In the below code we will try to add space and dot.  so now the expression allows alphabets, numbers space and dot.

var rStr1 = str.replace(/[^a-zA-Z0-9 .]+/g, '');
alert(rStr1);
Output: This is sample sting from .NET Mirror Ready 123Go

SET IDENTITY_INSERT for Table Variable in SQL Server


SET IDENTITY_INSERT - Allows to insert explicit values to identity column of the table.

SET IDENTITY_INSERT ON/OFF works for talbes and temporary table.
we can not use for table variables.

If we run a sample query below
DECLARE @student TABLE (ID INT IDENTITY,Name VARCHAR(50))
 
INSERT INTO @student(Name) Values('A')
INSERT INTO @student(Name) Values('B')
INSERT INTO @student(Name) Values('C')
INSERT INTO @student(Name) Values('D')
 
DELETE FROM @student WHERE ID = 3
 
SET IDENTITY_INSERT @student ON
 
INSERT INTO @student(ID,Name) Values(2,'E')

we will get error as
Msg 102, Level 15, State 1, Line 10
Incorrect syntax near '@student'



28 August 2012

Color themes with Visual studio 2012 and How to Change theme


Visual studio 2012 has 2 types of themes (Dark and Light). You can see the sample screenshots below.

If you want to change/switch the theme, you can do from Tools  Options Environment General Color theme select the dropdown items which has(Dark/Light).

Dark Theme look:



Dark Color theme VS2012
Light Theme look
Light Color theme VS2012
 

27 August 2012

Page.RouteData is null or Page not found in URL routing


If we are using ASP.NET URL rewriting concept, you might Registered routes correctly in Global.aspx like below


  protected void Application_Start(object sender, EventArgs e)
    {
        RegisterRoutes(RouteTable.Routes);
    }

  public static void RegisterRoutes(RouteCollection routeCollection)
    {
        routeCollection.MapPageRoute("RouteArticle", "Articles/{Id}", "~/Resources/ViewArticle.aspx");
}

 ViewArticle.aspx.cs:


int resourceContentID = int.Parse(Page.RouteData.Values["Id"].ToString());
 
From the browser if you try to access the page(http://localhost/website/articles/13) ,sometimes we will get run time error as Page.RouteData as null or HTTP page not found in browser.

In order to avoid the error add below section to web.config file. 

<configuration>
       <system.webServer>
              <modules runAllManagedModulesForAllRequests="true"/>
       </system.webServer>
</configuration>

24 August 2012

Microsoft changed the logo after 25 years

After 25 years, Microsoft has changed the logo on 23-Aug-2012. The new look you can find from microsoft sites.

The new logo looks like










For more info : http://blogs.technet.com/b/microsoft_blog/archive/2012/08/23/microsoft-unveils-a-new-look.aspx

22 August 2012

What is the meaning of # in C#


The name "C sharp" was inspired by musical notation where a sharp indicates that the written note should be made a semitone higher in pitch. This is similar to the language name of C++, where "++" indicates that a variable should be incremented by 1.
Due to technical limitations of display (standard fonts, browsers, etc.)    and the fact that the sharp symbol (♯ music sharp sign) is not present on the standard keyboard, the number sign (# number sign) was chosen to represent the sharp symbol in the written name of the programming language. This convention is reflected in C# Language Specification.

Microsoft has used this # symbol in other languages like F#, J#.
Source : wiki