I need to display a submission form inside a lightbox of an ASP.NET page.
If there is an error in the submission form such as user name not being unique, the postback then renders the ASP.NET page outside the lightbox.
How can I solve that problem?
Here is a code snippet of the .aspx page that includes the 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">
> 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> </p><p> </p>
<...>
contactform.aspx is just a standard .aspx page with form fields, field validators, label to display errors (e.g. username not unique) and submit button.
When a postback occurs on contactform.aspx then (of course) it is rendered outside the lightbox. How can I display the postback of contactform.aspx inside the lightbox?
Thanks for your help!
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.)
Related
In my project I want to run 2 forms in one webpage which is master page one is for contact us and one is for signup user. but multiple server side forms are not allowed. is there any solution for fix it?
You can use postback ability of Asp.net Webforms.
You should create one button for singup and another one for contact. You can catch event in server side and you do what want to do.
You can create regular client side forms created using HTML in the master page, and use the Request.Form to read the posted data. For this to work, all the input elements must have a name, and you can read them using Request.Form["ElementName"].
Take into account that forms cannot be nested.
So, your master page needs to llok like this
...
<body>
<form id="form1" runat="server">
</form>
<form id="contact" action="Contact.aspx" method="post">
<input type="text" name="Message"/>
<input type="submit" value="Contact us!"/>
</form>
</body>
The first <form> is the regular ASP.NET server side form, which supports server side components
The second <form> is a custom HTML form. It doesn't have the runat="server" attribute, and it's outside the server side <form>.
The second form action points to a .aspx page. In its page load event you can use the Request.Form["Name"] to acces the name of the contact form. Note that you also need to include a submit button to send the data to the server, and a method="post" to specify the method to send the page.
This is resorting to "basic" HTML controls, so there is no View State, and the posted values will be lost if they're not reset in the server. I.e. if the form is posted, and there's an error, the previously posted values will be lost when rendering the page again.
If you want to make it more sophisticated you can use Javascript and, optionally AJAX. But that's a more complex solution. See this for an example.
ASP.NET Forms only supports one form. You could use an iFrame and render your second page (second form) inside of the iFrame.
Here is an interesting post about placing some page content after the tag. This may be helpful to you.
http://forums.asp.net/t/1611822.aspx?Dynamically+adding+content+to+page+outside+of+the+aspnet+form+from+within+a+UC
I am scraping an ASP.net page with Scrapy which displays a paginated list of items. To navigate through the items, there are next and previous buttons in the following format:
<form name="aspnetForm" method="POST" action="search_active_main.aspx" id="aspnetForm">
<!-- other content here -->
<!-- previous button -->
<input type="image" name="ctl00$gvMain$ctl01$btnPrevious" id="ctl00_gvMain_ctl01_btnPrevious" src="/image/previous.gif" />
<!-- next button -->
<input type="image" name="ctl00$gvMain$ctl01$btnNext" id="ctl00_gvMain_ctl01_btnNext" src="/image/next.gif" />
<!-- other content here -->
</form>
When you click one of the buttons, something like this is sent as part of the POST:
ctl00$gvMain$ctl01$btnNext.x:37
ctl00$gvMain$ctl01$btnNext.y:10
What do these numbers represent / how can I crawl through them without using something like Selenium?
As Obsidian Phoenix suggests, the numbers represent the coordinates of the button that is clicked. To crawl the page, you just have to POST the following as formdata in FormRequest to simulate a next button click:
FormRequest.from_response(
response,
formdata={
'ctl00$gvMain$ctl01$btnNext.x':'1'
'ctl00$gvMain$ctl01$btnNext.y':'1'
},
dont_click=True,
dont_filter=True,
callback=self.your_callback_function
)
One thing to investigate is the URL that is present on each page. You may find subsequent pages have /2 /3 etc in their URL but otherwise be identical.
If that's the case, then you can bypass the need to click any buttons and just reload the page with the new page number.
I have a Contact userControl that have "save contact" as submit button and fields inside form tag we repeat this userControl with Code 20 times in one page
My problem is the Form Tag in the first userControl is hiding somehow --- i checked the userControl with developer Tool IE9 , firebug Firefox7 and the Form is not appearing in the first userControl and its appearing with the rest 19 Controls
I tried to View Source and take html copy in new html file in VS -- i found form is exist
i dont know if iam clear enough but please advice if you need more info
If you're running a form tag at the server, inside a user control, and then displaying this user control more than once on the page, then you will have multiple form tags running at server on one page, which is not allowed by ASP.NET
Take the form tag outside of the user control like:
<form runat="server">
<uc:Contact />
<uc:Contact />
<uc:Contact />
</form>
Is there a good way to enable forms that come out of user content (CMS) that is displayed inside the form runat="server" tag? All sorts of services provide forms for users to paste into their website, which break if the content ends up inside a .net form. It seems to me that there must be a good way around this, but I can't seem to find any solutions.
The one solution I've found is to put them in an IFRAME. So instead of embedding your form inside the page:
<FORM action="http://www.example.com/target.html">
.. form content
</FORM>
create a new ASPX file like this:
<FORM action="http://www.example.com/target.html" target="_top">
.. form content
</FORM>
Then in your original page, you'll refer to it via an IFRAME:
<IFRAME src='myform.aspx'></IFRAME>
Some things you'll need to do:
Make sure that you do not include any <FORM runat="server"> inside the new ASPX file.
Adjust the size of the IFRAME and the ASPX file to be exactly the same
For the FORM in the new ASPX files, you probably want to set target='_top' to ensure when a user fills in the form, the result is in the main window rather than inside the IFRAME.
I'm fixing a customer site designed in ASP.NET, using Master pages. I need to put a jQuery adgallery inserted in a Content page which is linked to the master page.
<asp:Content ContentPlaceHolderID="cphHeader" runat="server">
<div class="ad-gallery">
</div>
</asp:Content>
Since that Content renders in server-side, the jQuery ad gallery does not work.
What workaround, if available, I can use to insert a jQuery gallery in this Master page placeholder?
It looks like you might be trying to put the in the Content placeholder intended for the html head element of your master page (this is from the id of the content placeholder). In a ASP.Net content page typically you have two content placeholders one that is for the head element and one for the body element. So in the head content placeholder you would put your scripts and other resources in the body content placeholder you would put your html markup such as the div.
For the second part of your question if you use $(document).ready() and wireup your gallery from there you are assured that the DOM elements you are trying to work with will be loaded on the page.