ASP.NET 页面上的多个表单 [英] Multiple forms on ASP.NET page

查看:23
本文介绍了ASP.NET 页面上的多个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自经典 ASP 背景,我习惯于在一个页面上使用多个表单,但这显然仅限于 ASP.NET 页面.

Coming from a Classic ASP background, I'm used to multiple forms on a page, but this clearly limited in a ASP.NET page.

但是,我有一个表单可以收集用户的输入,将数据保存到数据库,然后我想呈现(并调整其值)一个特殊的表单,该表单发布到 PayPal 网站.

However, I have a situation where I have a form that gathers input from the user, saves the data to a DB, and afterwards I want to render (and tweak the values of) a special form that posts to the PayPal website.

如果 PayPal 表单的字段值是静态的,那就没有问题,但是由于我想在服务器端操作表单(调整数量、描述、价格字段等),这 有问题.

If the PayPal form's field values were static, there would be no problem, but since I want to manipulate the form server-side (to tweak the qty, desc, price fields etc) this will be a problem.

我正在考虑在写入数据库后重定向到不同的页面,我怀疑这会工作得很好,但是这可能是不必要的额外努力.

I was considering redirecting to a different page after writing to the DB, and I suspect this would work fairly well, but it's a bit of extra effort that may be unneccessary.

我还建议我可以根据我在循环中的位置以编程方式呈现不同的形式.也就是说,使用占位符,在 Page_Load 上,我最初会添加一个 DB 表单(带有子控件),然后在回发后添加 PayPal 表单.

It has also been suggested to me that I could programmatically render a different form, depending on where in the cycle I am. That is, use a placeholder, and on Page_Load I would add a DB Form (complete with child controls) initially, and the PayPal form after a Postback.

对于你们来说,这种情况必须是常见的,所以如果您有更喜欢的方法,我正在寻找意见建议和任何相关的代码示例.

This scenario has got to be a common one for you guys, so I'm looking for opinions advice and any relevant code samples if you have preferred approach.

我知道我能过得去,但这个项目是一个学习工具,所以我想采用最佳实践.

I know I can get by, but this project is a learning vehicle so I want to adopt what passes for best practice.

提前致谢...

克里斯

推荐答案

你可以有多个表单,只有一个表单可以有 runat="server" 属性.

You can have multiple forms, it's just only one form may have the runat="server" attribute.

让 PayPal 工作的答案有很多;但因为它是一种可能会作弊的学习工具.老实说,我会看一下成熟的 PayPal API,而不是使用某种形式过于简单的方法(还有一个额外的好处,那就是它应该可以扩展您的学习范围).

There are a bunch of answers to getting PayPal to work; but as it's a learning vehicle that may be cheating. In all honesty, I'd look at the full-blown PayPal API rather than use the method of the somewhat simplistic form (with the added advantage that it should stretch your learning more).

否则是的,在服务器端表单之外设置一个 HTML 表单,并在其中添加一个文字并在其中写入零碎的内容.

Otherwise yes, set up an HTML form outside of the server side form, and add a literal into it and write the bits and pieces in there.

这篇关于ASP.NET 页面上的多个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆