Problem:
Error message: unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

This error normally occurs when you use Response.Redirect, Server.Transfer or Response.End in your code before completing the actual process the page was doing.
Solutions:
a. In place of Response.End, use HttpContext.Current.ApplicationInstance.CompleteRequest
b. In place of Response.Redirect(url), use:
Response.Redirect(url, false);
Where:
Redirect()'s second parameter (bool) indicates whether execution of current page should terminate.
c. In place of Server.Transfer, use Server.Execute method
For more information, see here.