Monday, 23 June 2014

validation of viewstate MAC failed in ASP.NET Web Form

validation of viewstate MAC failed

There are few reason for this error. Below is one of them.

Check the idle time of application pool in IIS and try to increase.

  1. Open IIS
  2. Click on application pools node
  3. Locate your web application's application pool
  4. Right-Click and select Advanace Settings
  5. Set the Idle Time-out(minutes) property to 0 or increase 


Wednesday, 19 February 2014

XML to Object serialization in ASP.NET Web API

Simple XML to Object serialization


class Student
public string Name;


  public string ProcessXML(Student s)

Global asax.cs

var xml = GlobalConfiguration.Configuration.Formatters.XmlFormatter;
                 xml.SetSerializer<Student>(new XmlSerializer(typeof(Student))); 

Now you can post XML data as below

Tuesday, 4 February 2014

Get gridview row data in c#


  <asp:GridView ID="grid" runat="server" AutoGenerateColumns="false"            onrowcommand="grid_RowCommand" >
 <asp:TemplateField >
 <asp:TextBox ID="txt"  runat="server" Text='<%#Eval("xxx") %>'  >                   </asp:TextBox>
 <asp:TemplateField >
<asp:LinkButton ID="lnk" CommandArgument=<%# Container.DataItemIndex + 1 %> CommandName="arg">Click</asp:LinkButton>


 protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
int rowindex = int.Parse(e.CommandArgument.ToString());

Wednesday, 22 January 2014

Deserialization of an XML to an object in C#

Deserialization of an XML to C# class

<Book Title="My Book">
   <Publisher Reference="XYZ123">Some Publisher</Publisher>


public class Book
   public string Title;

   public Publisher Publisher;

public class Publisher
  public string Value;

  public string Reference;
Book res = new Book(); 
XmlTextReader reader = new XmlTextReader("file path"); 
res = (Book)serializer.Deserialize(reader);