Intermittent Invalid Viewstate Error in ASP.NET Web pages [Resolved]

Posted by Cpatil1000 under ASP.NET on 10/14/2016 | Points: 10 | Views : 477 | Status : [Member] | Replies : 1
Im developing a Chart that is displaying Farmer Status (current status, pending status etc...)
the for the click status from a reapter using linkbutton it is working ...
but when i close google chart and try to selet another farmer status it getting error ... *

[ViewStateException: Invalid viewstate.
Client IP: ::1
Port: 27968
Referer: http://localhost/HolidayTracker/Report/VacationChart.aspx
Path: /HolidayTracker/Report/VacationChart.aspx
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
ViewState: ....

protected void rpStatus_ItemCommand(object source, RepeaterCommandEventArgs e)
{
try
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if (e.CommandName == "Status")
{
this.dgFarmerDetail.DataSource = null;
this.dgFarmerDetail.DataBind();

this.dFarmerDetails.Visible = false;

this.dDetailHead.Visible = false;
this.dfarmerHead.Visible = false;

StatusID = Convert.ToInt32(e.CommandArgument);

this.SetFarmerChart();
ScriptManager.RegisterStartupScript(this, this.Page.GetType(), "updatePanel1Script", "javascript:drawFarmerChart();", true);
}
}
}
catch (Exception ex)
{
throw ex;
}
}

public string SetFarmerChart()
{
DataTable sourceFarmer = null;
StringBuilder returnFarmerValue;
int incVal;
FarmerLogic farmerLogic;
FarmerEntity farmerEntity;

try
{
returnFarmerValue = new StringBuilder();

farmerEntity = new FarmerEntity();

if (StatusID == 0)
{
farmerEntity.UserID = GM.UserID;
farmerEntity.StatusID = 0;
}
else if (StatusID > 0)
{
farmerEntity.UserID = GM.UserID;
farmerEntity.StatusID = StatusID;
}

farmerLogic = new FarmerLogic();

sourceFarmer = farmerLogic.SelectFarmerMasterStatusChart(farmerEntity);

if (sourceFarmer == null) { sourceFarmer = null; return string.Empty; }
if (sourceFarmer.Rows.Count <= 0) { sourceFarmer = null; return string.Empty; }

if (sourceFarmer.Rows.Count > 0 && Convert.ToInt32(sourceFarmer.Rows[0]["TotalStatus"].ToString()) != 0)
{
returnFarmerValue.Append("data.addColumn('string', 'Status');");
returnFarmerValue.Append("data.addColumn('number', 'TotalStatus');");

returnFarmerValue.Append("data.addRows(" + sourceFarmer.Rows.Count + ");");

for (incVal = 0; incVal < sourceFarmer.Rows.Count; incVal++)
{
returnFarmerValue.Append("data.setValue(" + incVal + ", 0, '" + sourceFarmer.Rows[incVal]["Status"] + "');");
returnFarmerValue.Append("data.setValue(" + incVal + ", 1, " + sourceFarmer.Rows[incVal]["TotalStatus"] + ");");
}

return returnFarmerValue.ToString();
}
else
{
return returnFarmerValue.ToString();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
sourceFarmer = null;
farmerLogic = null;
farmerEntity = null;
}
}





Responses

Posted by: Rajnilari2015 on: 10/15/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Please check this link( https://support.microsoft.com/en-in/kb/555353 ) .That will help

--
Thanks & Regards,
RNA Team

Cpatil1000, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response