Question

Je dois afficher un formulaire de soumission à l'intérieur d'une Lightbox d'une page ASP.NET. S'il y a une erreur dans le formulaire de soumission telle que le nom d'utilisateur n'étant pas unique, le post-pack rend la page ASP.NET à l'extérieur de la Lightbox. Comment puis-je résoudre ce problème?

Voici un extrait de code de la page .aspx qui inclut la Lightbox:

<...>
<p>
    QunatumMotors is located in Detroit. Please use the link below to contact us.</p>
<p>
 <!--START CONTACT FORM OVERLAY-->

        <!-- first overlay. id attribute matches the selector -->
        <a href="**../informational/contactform.aspx"** rel="#overlay" style="text-decoration:none">
        &gt; Click here to contact us
        </a>

        <div class="simple_overlay" id="form_contact">
            <!-- overlayed element -->
            <div class="apple_overlay" id="overlay">
                <!-- the external content is loaded inside this tag -->
                <div class="contentWrap"></div>
            </div>
        </div>
 <!--END CONTACT FORM OVERLAY-->

<p>&nbsp;</p><p>&nbsp;</p>
<...>

ContacterForm.aspx est juste une page standard .aspx avec champs de formulaire, validateurs de champ, étiquette pour afficher les erreurs (E.G. Nom d'utilisateur non unique) et bouton Soumettre. Lorsqu'un post-plan a lieu sur ContactForm.aspx, alors (bien sûr), il est rendu en dehors de la Lightbox.Comment puis-je afficher le message de contact de contactform.aspx à l'intérieur de la Lightbox? Merci pour votre aide!

Était-ce utile?

La solution

The lightbox content isn't like another tab or window: it becomes part of the host page.

In other words, it incorporates the HTML generated by contactform.aspx into the host page's document object model (DOM). Activating the lightbox adds a form to the host page that posts to the contact page:

 <html><body>
     <!-- host page content here -->
     <!-- contact form content -->
     <form action="contactform.aspx">
         <!-- text boxes, buttons, etc. -->
     </form>
 </body></html>

When the user submits, their browser issues a new request: a POST to contactform.aspx. That request returns the contact form's HTML.

There are several ways you might work around that:

  • Use ajax to perform the update asynchronously. (You might even be able to do this by using an UpdatePanel in contactform.aspx, but I don't use them much anymore and haven't though that through).

  • Convert contactform.aspx into a control (if you're using it in several places) and embed it in the host page.

  • At the end of the contact form's submit handler, redirect to the host page with a flag that instructs the page to immediately activate the lightbox. (This has numerous issues and sounds pretty fragile ... but it's plausible.)

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