100% code-behind form post
I am l开发者_JAVA技巧ooking for a way to wire up an ASP:LinkButton to appear as a link but in the background (100% in the code behind, no dummy pre-filled form in the markup) do a form post (target=_blank). I have a form action, method and parameters to pass that I will query for in the "click" event of the LinkButton. What is the best way to accomplish this?
Well there are LOTS of ways to do what i think you are trying to do :)
One problem; standard pop-up's don't fire event handler calls as they are mapped via post-back to the page i believe.
If you are happy with GET only submissions:
OPTION A: Add your link button with no target set and setup a post back event handler for click
setup your URL and pass it back to the page into a JS function that will load right away eg or use jquery etc.
in the JS function you load the URL using window.open() with the target set to "_blank"
EFFECT: User clicks the link, all code is server-side that works out the URL to show, page refreshes back to where it was and a popup window then loads showing the new URL
OPTION B: Setup the link to have target="_blank"
make it call a new page or the same page with a querystring argument you can pre-process in the page_load()
in the new page or controlling block of code, do your calculations and Response.Redirect() to the new target
EFFECT: User clicks the link, no page refresh just a new popup right away with a redirect to the new page. This is a cleaner solution i think!
IF you need POST support:
Dynamically create either elements or a string of HTML representing a form with all the needed input elements and output it into the popup window (using option b as a rough start template) and have a onload submit the form right away which will perform a POST to the URL you decided via server-side script giving the same effect as option b but with a form level POST.
精彩评论