asp.netautopostback

How to resolve " a control with id X could not be located or a different control is assigned to the same ID after post back" in asp.net?


Please help me to rectify this error.

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

This error occurred on a post back by an asp button click. All the controls in the page were dynamically generated. I tried to find this control in the page source but in vain.

    HtmlGenericControl td1 = new HtmlGenericControl("td");
    TextBox txt1 = new TextBox();
    txt1.ID = "toqty"+i.Tostring();
    td.controls.add(txt1);
    placeholder.controls.add(td);

Solution

  • Since the error has occured due to a button click, the controls that where generated before the button click might have been cleared from your corresponding form. So i recommend you to check out the methods or codes that were written after the button click by pinning a breakpoint on the button_click() method. Try this and please leave a reply.