  Using a set of general methods developed by Krotov [A. I. Konnov and V. A.
Krotov, Automation and Remote Control, {\bf 60}, 1427 (1999)], we extend the
capabilities of Optimal Control Theory to the Nonlinear Schr\"odinger Equation
(NLSE). The paper begins with a general review of the Krotov approach to
optimization. Although the linearized version of the method is sufficient for
the linear Schr\"odinger equation, the full flexibility of the general method
is required for treatment of the nonlinear Schr\"odinger equation. Formal
equations for the optimization of the NLSE, as well as a concrete algorithm are
presented. As an illustration, we consider a Bose-Einstein condensate initially
at rest in a harmonic trap. A phase develops across the BEC when an optical
lattice potential is turned on. The goal is to counter this effect and keep the
phase flat by adjusting the trap strength. The problem is formulated in the
language of Optimal Control Theory (OCT) and solved using the above
methodology. To our knowledge, this is the first rigorous application of OCT to
the Nonlinear Schr\"odinger equation, a capability that is bound to have
numerous other applications.
