"Control with id could not be located or a different control is assigned to the same ID after postback." Error

StackOverflow https://stackoverflow.com/questions/21251756

Question

I have a web-application in .NET framework 4.5 with code behind C#.

I am using a RadGrid of telerik Asp.Net Ajax control. I am creating it dynamically from code behind in PageInit event and adding it to a div that is statically defined in aspx file.

Now, for each row I am having a button that is used to expand and collapse the row using JQuery script.

I also have a RadCalendar on the page and I am fetching records according to selected date range.

Now, the problem is, if I select a date range from 1st to 16 days, it works fine. If I select 1st to 30 days then also there is no problem. But now if I select 1st to 8, it gives me the error show below :

Server Error in '/' Application.
An error has occurred because a control with id 'ctl00$ContentPlaceHolder1$gvGridViewDemo$ctl00$ctl09$Detail20$ctl06$Detail10$ctl04$ctl10' 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. 

I am NOT using any ajax in this page, so on date selection it gets full postback. Also I had set viewstate to false, ViewstateMode to disable and ClientId = autoId for both - Button and Gridview. But I am not able to get rid of this.

Can anyone help me to get rid of this ridicules error?

P.S. I have checked the link An error has occurred because a control with id {0} could not be located or a different control is assigned to the same ID after postback and according to the comment I am having string.format() in my code. But I have commented it and still I am facing the same issue.

Était-ce utile?

La solution

Resolved it by myself. I do not consider it to be the great solution I have discovered but I am answering this question that it might help someone who wants to get rid of this kind of issue and tired of finding the exact solution.

I have solved it by debugging skills with Trial and Error methodology (it requires so much patience in oneself).

What I did is, I started commenting some of the code that places dynamic controls on the page and checked for result whether the same error is generated or not? If yes, then you are commenting wrong code. So just remove the comments, make that portion as it was and move on.

At last I found that there were some dynamically generated tool-tips; I was used to display some additional details on every cell of the grid view (RadGrid), were creating this error. On PageInit I was clearing all of the controls of the division and adding a grid view by code behind. So each time the request gets initiated, it clears all of the controls and adds them newly.

However, the objects of tool-tip (I have used RadTooltip to display the tool-tip on cell) were not getting cleared from the page across the postbacks.

So I just applied a new ID to each tool-tip using its cell's (cell of grid) client id + DateTime.Now.Ticks.ToString(), and I kicked off myself from this weird error.

Autres conseils

I see you solved it, yet this may be useful in the future if you have problems with RadTooltip, I had a couple of issues resolved with this: http://www.telerik.com/help/aspnet-ajax/tooltip-troubleshooting-common-issues.html.

I was getting this problem too. What fixed it was explicitly adding ID values to all the Control objects I was dynamically loading onto my screen.

It happens for me when I have multiple command field in my grid view. I converted them to template fields and everything worked fine!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top