I have radgrid with
OnDeleteCommand
="Grid_DeleteCommand"
protected
void Grid_DeleteCommand(object source, GridCommandEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.Item;
string name= dataItem["Name"].Text;
try
{
var Id= (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"];
DeleteItem(Id);
InsertGridMessage("Name: " + name+ " is deleted!", false);
}
catch (Exception ex)
{
InsertGridMessage(
"Name: " + name+ " cannot be deleted. Reason: " + ex.Message, true);
e.Canceled =
true;
}
}
private
void InsertGridMessage(string message, bool isFailure)
{
var lblMessage = new Label
{
ID =
"LblGridMessage",
Text = message,
ForeColor = isFailure?
Color.Red:Color.Green
};
Grid.Controls.AddAt(0, lblMessage);
}
When i delete the item for first time it all works fine. But any action on radgrid will throw following exception. The reason is because the viewstate is not updated. Any ideas?I get following error
Webpage error details
Message: Sys.WebForms.PageRequestManagerServerErrorException: Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
Line: 6
Char: 84093
Code: 0
URI: https://localhost/EzURWeb/Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScripts_=%3b%3bSystem.Web.Extensions%2c+Version%3d4.0.0.0%2c+Culture%3dneutral%2c+PublicKeyToken%3d31bf3856ad364e35%3aen-US%3a8f393b2b-3315-402f-b504-cd6d2db001f6%3aea597d4b%3ab25378d2%3bTelerik.Web.UI%3aen-US%3acf630f82-0e77-4618-bf5c-22b81f4ec1c5%3a16e4e7cd%3af7645509%3a22a6274a%3a24ee1bba%3ae330518b%3a1e771326%3ac8618e41%3aed16cbdc%3a86526ba7%3a8e6f0d33%3aaa288e2d%3aa7e79140%3a6a6d718d%3a874f8ea2%3a19620875%3a33108d14%3a8674cba1%3ab7778d6c%3ac08e9f8a%3aa51ee93e%3a59462f1