100% 代码隐藏表单发布
我正在寻找一种方法来连接 ASP:LinkButton 以显示为链接,但在后台(100% 在后面的代码中,标记中没有虚拟的预填充表单)执行表单发布 (target=_blank)。我有一个要传递的表单操作、方法和参数,我将在 LinkButton 的“单击”事件中查询它们。实现这一目标的最佳方法是什么?
I am looking 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,有很多方法可以做我认为你想做的事情:)
一个问题;标准弹出窗口不会触发事件处理程序调用,因为它们是通过回发映射到我认为的页面的。
如果您对仅 GET 提交感到满意:
选项 A:
添加没有设置目标的链接按钮,并设置一个回发事件处理程序,用于单击
设置您的 URL 并将其传递回页面到将立即加载的 JS 函数,例如或
在您加载 URL 的 JS 函数中 使用 jquery 等使用 window.open() 并将目标设置为“_blank”
效果:
用户单击链接,所有代码都在服务器端计算出要显示的 URL,页面刷新回原来的位置,然后加载一个弹出窗口,显示新的 URL
选项 B:
将链接设置为 target="_blank"
使其调用新页面或带有查询字符串参数的同一页面,您可以在新页面或控制代码块的 page_load() 中进行预处理
,进行计算和响应。 Redirect() 到新目标
效果:
用户单击链接,不会刷新页面,只会立即弹出一个新页面,并重定向到新页面。我认为这是一个更干净的解决方案!
如果您需要 POST 支持:
动态创建表示包含所有所需输入元素的表单的元素或 HTML 字符串,并将其输出到弹出窗口(使用选项 b 作为粗略的启动模板),并让 onload 立即提交表单它将对您通过服务器端脚本决定的 URL 执行 POST,其效果与选项 b 相同,但具有表单级别的 POST。
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.