Tuesday, 20 March 2012

Validation of viewstate MAC failed.

"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."

Set EnableViewStateMac="false" for Specific page then set on page directory
<%@ PageLanguage="C#"AutoEventWireup="true"CodeFile="Dashboard.aspx.cs"Inherits="_Default"  EnableViewStateMac="false" %>
For all page then this will set on webconfig file
<page EnableViewStateMac="false">
page >

Saturday, 17 March 2012

Detect the browser using ASP.NET and C#


System.Web.HttpBrowserCapabilities browser = Request.Browser;
stringbtype=   browser.Type.ToString();

GridView must be placed inside a form tag with runat=server

Control 'grvtype' of type 'GridView' must be placed inside a form tag with runat=server

Here I will explain how to solve the problem Control 'grvtype' of type 'GridView' must be placed inside a form tag with runat=server during if u want to render
Grid view control in HtmlTextWriter
pnlResults.RenderControl(new HtmlTextWriter(new System.IO.StringWriter(sb)));

Control 'grvtype' of type 'GridView' must be placed inside a form tag with runat=server

This error occurs whenever I am trying to export gridview data to excel or word or csv because compiler thinks that the control is not added to the form.  

To solve this problem I have added one overriding function VerifyRenderingInServerForm event in code behind it solves my problem. 

public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
By Setting adding this function in code behind that problem has solved and code runs successfully.

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger