
    Betty PECKMANN, Kim Perry, William Dick, and Kimberly Dick, all on their own behalf and on behalf of separate Plaintiff classes, Plaintiffs-Appellees, Cross-Appellants, v. Robert THOMPSON, in his official capacity as Director of the Illinois Department of Professional Regulation, Bernard Turnock, in his official capacity as Director of the Illinois Department of Public Health, Neil Hartigan, in his official capacity as Attorney General of the State of Illinois, and Thomas Difanis, Gregory Grigsby, Nancy Owen, Richard Goff, Richard Broch, Tony Lee, John Turner, Lawrence Fichter, Charles Reynard, John Robinson, Kevin Lyons, Roger Simpson, Eric Blanc, and John Huschen, all in their official capacity as State’s Attorneys and on their own behalf and on behalf of all Defendant class State’s Attorneys in Illinois, Defendants-Appellants, Cross-Appellees.
    Nos. 90-3334, 90-3445.
    United States Court of Appeals, Seventh Circuit.
    Argued May 26, 1992.
    Decided July 2, 1992.
    Edward Zukosky, argued, Wenona, III, William C. Zukosky, Urbana, Ill., George F. Taseff, argued, Jennings, Novick, Taseff, Smalley & Davis, Bloomington, Ill., for plaintiffs-appellees, cross-appellants and amicus curiae Marsden Wagner, International Ass’n of Parents and Professionals for Safe Alternatives in Childbirth.
    Neil F. Hartigan, Atty. Gen., Chicago, Ill., Randy E. Blue, Asst. Atty. Gen., Criminal Appeals Div., Springfield, Ill., Jennifer A. Keller, Asst. Atty. Gen., argued, Civil Appeals Div., Chicago, Ill., Kenneth R. Boyle, Patrick Delfino, State’s Atty. Appellate Prosecutor, Springfield, Ill., for defendants-appellants, cross-appellees.
    David M. Smolin, Samford University, Cumberland Law School, Birmingham, Ala., Douglas H. Scofield, Birmingham, Ala., for amicus curiae Southern Center for Law and Ethics.
    Before BAUER, Chief Judge, COFFEY, Circuit Judge, and WOOD, Jr., Senior Judge.
   BAUER, Chief Judge.

On November 16, 1989, plaintiffs, a traditional midwife, an apprentice midwife, and a couple who seek to use the services of a midwife, brought suit individually and on behalf of the classes of persons ■ similarly situated, against the Director of the Illinois Department of Professional Regulation, the Director of the Illinois Department of Public Health, the Attorney General of the State of Illinois (all in their official capacities, hereinafter “the state defendants”), and the State’s Attorneys of fourteen Illinois counties (in their official capacities and on their own behalf and on behalf of the class of all State’s Attorneys in Illinois, hereinafter “the county defendants”). The complaint alleges that the State’s failure to license traditional midwives and its construction of the Illinois Medical Practice Act of 1987, Ill.Rev.Stat. ch. Ill, paras. 4400-1 thru 4400-63, violate rights guaranteed under the First, Ninth, and Fourteenth Amendments.

As their initial pleading, the state and county defendants filed separate motions under Federal Rule of Civil Procedure 12(b)(1) to dismiss for want of a substantial federal question. Memoranda of law accompanied both motions, but neither included affidavits or other evidentiary materials. Plaintiffs responded to both motions with their own memorandum of law, and attached thereto uncertified copies of indictments against Peckmann and Perry for practicing medicine without a license, and a copy of a nolle prosequi motion withdrawing those charges. Plaintiffs submitted these latter documents in support of allegations in the complaint that (1) Peckmann and Perry were indicted for practicing medicine without licenses, and (2) the charges were dismissed on the condition that plaintiffs would file an action in federal court to litigate their constitutional claims. Additionally, plaintiffs attached to their memorandum copies of opinions and orders issued by courts of other jurisdictions.

These were all the documents before the district court when it heard oral argument on defendants’ motions on May 2,1990. At the hearing’s conclusion, the district court took the matter under advisement. Four months later, on September 19, 1990, 745 F.Supp. 1388, the district court issued its order denying defendants’ motions to dismiss and entering summary judgment in favor of plaintiffs. It concluded that, although the state, within its police power, may prohibit the practice of midwifery, sections 4400-49 and 4400-50 of the Illinois Medical Practice Act of 1987 are unconstitutionally vague.

Defendants filed a timely joint notice of appeal. Plaintiffs cross-appealed. Because of our resolution of the first argument defendants raise, we need not address their remaining arguments, nor those plaintiffs raise. Defendants claim, that the district court erred when it sua sponte entered summary judgment against them. We agree.

. [2-4] If a defendant’s Rule 12(b)(1) motion is an indirect attack on the merits of the plaintiff’s claim, the court may treat the motion as if it were a Rule 12(b)(6) motion to dismiss for failure to state a claim upon which relief can be granted. Malak v. Associated Physicians, Inc., 784 F.2d 277, 280 (7th Cir.1986). The rule further provides that if, on a 12(b)(6) motion,

matters outside the pleading are presented to and not excluded by the court, the motion shall be treated as one for summary judgment and disposed of as provided in Rule 56, and all parties shall be given reasonable opportunity to present all material made pertinent to such a motion by Rule -56.

Fed.R.Civ.P. 12(b).

This presupposes, of course, that a defense motion under Rule 12(b)(6) is converted into a defense motion under Rule 56. To enter judgment against a defendant sua sponte, however, is to turn the rule around and convert a defense Rule 12(b)(6) motion into a plaintiff’s Rule 56 motion. Although a permissible procedure, it is a hazardous one that warrants special caution. Horn v. City of Chicago, 860 F.2d 700, 703 n. 6 (7th Cir.1988); Sawyer v. United States, 831 F.2d 755, 759 (7th Cir.1987). The hazard is clear. The purpose of a motion for sum-, mary judgment is to look behind the pleadings to the proof to determine the existence, or nonexistence, of disputed factual issues, which determines the necessity for a trial. Kaplan v. 442 Wellington Co-op. Bldg. Corp., 567 F.Supp. 53, 56 (N.D.Ill. 1983). A district court cannot grant the motion unless “the pleadings, depositions, answers to interrogatories, and admissions on file, together with the affidavits, if any, show that there is no genuine issue as to any material fact and the moving party is entitled to a judgment as a matter of law.” Fed.R.Civ.P. 56. To grant the motion when the supporting documents the rule contemplates are not before the court is to deprive the nonmovant of the opportunity to be heard on the existence of disputed factual issues.

Defendants argue that even if their motion to dismiss for lack of subject matter jurisdiction could be construed as an attack on the merits of plaintiffs’ claims, summary judgment against them nonetheless was erroneous because they were not afforded the opportunity to present the court with affidavits or other materials. We agree. At the time the district court entered judgment, only the complaint, the defendants’ motions to dismiss, and the plaintiffs’ response were before it. Defendants had not yet answered the complaint, and thus had not formally notified the court or the opposing party which allegations it disputed. Nor had defendants filed any affidavits or supporting data with its motion to dismiss. Other than the extraneous material the plaintiffs filed along with their response to defendants’ motions, the district court had before it only the plaintiffs’ allegations, contained in the complaint, and legal memoranda submitted by all parties.

Moreover, defendants had no indication there was a need to file affidavits and other supporting data. At the hearing on the motions, the district court informed all present that “I don’t want to get into the facts of the case. At this point I’m looking for some legal framework that entitles [plaintiffs] to stay in court and litigate [constitutional rights].” Transcript of Hearing on Motion to Dismiss (“Tr.”), at 19. The district court made it clear that the only inquiry before it was whether it had subject matter jurisdiction. Tr. 23, 44. It gave no indication that it would reach the merits of plaintiffs’ claims, so defendants saw no reason to challenge them. The first defendants knew that factual issues as well as legal would be decided was when the district court entered its judgment against them. This was erroneous. Entry of summary judgment is improper when it comes as a surprise to the adverse party. Choudhry v. Jenkins, 559 F.2d 1085, 1089 (7th Cir.), cert. denied, 434 U.S. 997, 98 S.Ct. 634, 54 L.Ed.2d 491 (1977); Macklin v. Butler, 553 F.2d 525, 530 (7th Cir.1977).

For that reason, we remand the case to the district court to consider the arguments of the parties on issues of material fact. Counsel for the state defendants informed the court at oral argument that key provisions of the Illinois Medical Practice Act have been amended between commencement of this appeal and oral argument. With that in mind, counsel for both parties are instructed to address, and the district court to consider, the effect of that amendment on this action.

Remanded With Instructions.  