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

查看:70
本文介绍了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 Form(带有子控件),然后在Postback之后添加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天全站免登陆