Domanda

Devo visualizzare un modulo di invio all'interno di una lightbox di una pagina ASP.NET. Se è presente un errore nel modulo di invio come il nome utente che non è univoco, il postback quindi rende la pagina ASP.NET al di fuori della lightbox. Come posso risolvere quel problema?

Ecco uno snippet di codice della pagina .aspx che include 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>
<...>
.

ContactForm.aspx è solo una pagina standard .aspx con campi modulo, validatori di campo, etichetta per visualizzare errori (ad es. Username non univoco) e pulsante di invio. Quando si verifica un postback su ContactForm.aspx quindi (ovviamente) è reso all'esterno della lightbox.Come posso visualizzare il postback di contactform.aspx all'interno della lightbox? Grazie per il tuo aiuto!

È stato utile?

Soluzione

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.)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top