ASP.NET error a control with id could not be located or a different control is assigned to the same ID after postback

by Cliff 23. December 2008

Recently I came across an error in an asp.net page that took a fair amount of troubleshooting to resolve.  I had an asp.net page that was using a master page and within the aspx page, I had a grid view.  On the aspx page, I also had a drop down list that posted back to the server when the selected index changed.  On post back, I received the below error: 

An error has occurred because a control with id 'ctl00$ContentPlaceHolder1$gvFiles$ctl05$ctl00' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error.

System.Web.UI.Page.ProcessPostData

After some digging, I determined the error was due to multiple asp:ButtonField controls being placed in the GridView.  Since you can not assign an ID to these controls the above error was being raised.  I did not find out exactly why, but at a higher level, the issue was due to my master page having view state disabled.  Once I changed this so my master page had ViewStateEnabled="true" (I had previously set it to false) the error went away.  If you have viewstate turned off at the page or gridview level you may also encounter this issue.

Comments

July 19. 2009 15:19

Gravatar

Thanks for sharing this, I appreciate it.

David us

August 20. 2009 00:24

Gravatar

Hi Cliff,
Thanks for sharing this article.
View State is enabled by default, so i did not have to put that property on the grid or the page or the master page.
But one of the client still get this error.
Any ideas?
Thanks
J

J au

September 2. 2010 02:55

Gravatar

I think cliff got it wrong. This error is raised when the viewstate is enabled in the gridview which is the default. If you set it to false, the error will go away

:)

abideen us

Comments are closed

Cliff Gray's Info

Cliff Gray
Developer/Founder GrayTechnology.com.

E-mail me Send mail

Authors

Calendar

<<  October 2021  >>
MoTuWeThFrSaSu
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

Blogroll

Download BlogEngine.NET

Download at CodePlex

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2021

Subscribe