Search

Sep 30, 2008

Error: Validation of viewstate MAC failed

This is common error generally working with UpdatePanel.

On your screen you see message "Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster."

You can fix it in two ways, setting in web.config or in page it self.

In web.config:

<pages enableEventValidation="false" viewStateEncryptionMode ="Never" />



Or in page you write following line in @Page directive.




<%@ Page EnableEventValidation="false" ViewStateEncryptionMode="never" ...

Sep 25, 2008

Silverlight 2 Release Candidate Now Available

Hello All,

Silverlight 2 is now available, please read this post of Scott Guthre

Sep 24, 2008

with operator in JavaScript

Hello Friends,

I found one good thing in JavaScript, there is with operator in JavaScript, which you can say same as with operator in VB.NET. Its always helpful to define short name of big variable or replacement of such big variable; which lead us to make code more readable and maintain too.

In general when we are dealing with XML datasrouce in JavaScript; there always have long long variable name, of the value is so deep inside.

xmlDoc.childNodes[1].childNodes[0].childNodes[3].childNodes[0].text
xmlDoc.childNodes[1].childNodes[0].childNodes[4].childNodes[0].text

We have to write more lines of code to get all the details. Here we can use with, as we know part of path to reach final value is common which is xmlDoc.childNodes[1].childNodes[0], so we can put it into with keyword.

with(xmlDoc.childNodes[i].childNodes[0])
{
name = childNodes[1].childNodes[0].text;
add1 = childNodes[2].childNodes[0].text;
add2 = childNodes[3].childNodes[0].text;
email = childNodes[4].childNodes[0].text;
.
.
.
}

Sep 22, 2008

How to get Property list only of Derived class?

Hi All,

Recently I seen one requirement on ASP.Net Forum, some one posted question about How to get property list of Derived class.

Generally if we want to get all the property of class we use GetProperties() method. Which gives you the PropertyInfo[]. Lets see with example. We have following class Hierarchy.

class A
{
public int Id { get; set; }

public virtual void PrintMe()
{
Console.WriteLine("Id : " + Id);
}

}

class B : A
{
public string Name { get; set; }
public string Address { get; set; }
public override void PrintMe()
{
base.PrintMe();
Console.WriteLine("Name : " + Name);
}
}



In A there is only one property and in B we have 2 more property, our goal to get only two property declared in class B. Lets check with GetProperties().




PropertyInfo[] properties = typeof(B).GetProperties(); 


Console.WriteLine(properties.Count()); //will print 3



You can see its printing 3, that means it consider properties which are in parent and child too. There is one overload of GetProperties() which has BindingFlags, but with that also we are not achieving our goal.



So here is the solution using LINQ.




var prop =
from
p in typeof(B).GetProperties()
where p.DeclaringType == typeof(B)
select p;

Console.WriteLine(prop.Count()); //Will print 2



We are filtering on DeclaringType; which should be typeof(B). You can see now its returning 2, that what we needed.

Sep 21, 2008

Windows live writer for server 2003

Hello All,

This post is related to people who are creating blog using Window Live Writer.

It took me long to get the Windows Live Writer for Server 2003. Here is the link to download the Windows Live Writer for Server 2003

Sep 18, 2008

User Group Meeting on 20-Sep-2008

Hi All,

This is to announce that there is next meeting of Ahmedabad_SQLServer_UserGroup on Saturday, September 20, 2008.

I would like you to join this and meeting inperson and gain lots of knowledge shared by MVPs, there always a QA session at the end of each meeting followed by ICE-CREAM.

The topic of this meeting will be CTE and Pinal Dave [MVP] will be the speaker of this meeting.

To Register: Click Here.
To View Meeting Details : Click Here.
Not member of this group?: Click here

In previous meeting we explore the SQL Server Transaction Isolation Levels, which was presented by Jacob Sebastian [MVP, MSDN moderator, Owner of groups, and lots more], that was wonderful session along with live demos. If you miss that event then you can go here

Visual Studio IDE Support for SQL Server

Hello,

As we all know Visual Studio is now supporting Database project, which allows you to write query, procedure etc... from IDE only.

Recently I found the error while connecting SQL2008 from VS2008.

This server version is not supported. Only servers up to Microsoft SQL Server 2005 are supported.

I found after doing some googling; that there is no patch available which allos me to connect SQL2008 to VS2008!!!.

I found few comments which says that it will come soon.

Somasegar's WebLog
Euan Garden's BLOG

However there is Sservice Pack for Visual Studio 2008 Team Foundation Server which has ability to Support for SQL Server 2008, you can download that form Microsoft Download Center

Let me add that there is Service Pack for Visual Studio 2005 Support for SQL Server 2008, which you can download it from Microsoft Download Center

Sep 16, 2008

Reducing page load times with UpdatePanels and timers

Hi all,

Some time we have requirement like, on single page we are having 5-6 controls, which at the same tiem only single is visible and by navigation we can view all other controls.

This is very specific to Ajax Tab Implementation. Where we are having 4-5 tabs, in which we are having server controls, so on Page load all the controls get loaded and page become heavy also slow.

There is one technique to optimize this. As we all know we have to show single tab once page is get loaded, put all the controls into Asp:Panel and except one which we have to show on default; make other to visible false. The enable of all visible panel will be done using timer control. Time control will make enable the Asp:Panel one by one. As all the Asp:Panel will be in UpdatePanel will page will not get refreshed.

I found the same code in one of the post of Glavs Blog.

He provides the code along with video. Have a look at them and make optimize your page. I used this and found very good, even we can now use this on same page.

Sep 14, 2008

Why doesn't C# support multiple inheritance?

Hi all,

I was always searching for the answer of "Why doesn't C# support multiple inheritance?".

After some googling I found the answer from MSDN.

Please have a look at the link.

Sep 10, 2008

Finding occurrences of character in string [LINQ]

Hello All,

This is normal requirement when you need to find the occurrence of single character with in the string. Here is the example which uses LINQ to achive this.

string strString = "AA BRA KA DABRA";

var grp = from c in strString.ToCharArray()
group c by c into m
select new { Key = m.Key, Count = m.Count() };

foreach (var item in grp)
{
Console.WriteLine(
string.Format("Character:{0} Appears {1} times",
item.Key.ToString(), item.Count));
}