我有类似的事情:
<form id="Form1"> ... </form>
如何在C#代码隐藏中引用此表单?我试过简单地使用“Form1”,但它给了我一个错误。谷歌搜索也没有帮助。
我想要实现的是在Google Checkout“立即购买”按钮上动态输入项目名称或其中一个字段。请参阅:How to subscribe to click event of html form?。
答案 0 :(得分:2)
您需要运行表单服务器端:
<form id="Form1" runat="server> ... </form>
但是,如果您使用的是ASP.NET Web窗体,则每个运行服务器端的Web窗体只能有1个窗体。
编辑:看到您的修改后,我建议您使用Response.Redirect()
将值发布到您网站上的独立值:
Response.Redirect("GoogleCheckout.aspx?field=" + fieldvalue);
然后在这个独立页面上有以下内容:
<form action="https://sandbox.google.com/checkout/..." id="Form1" method="post" name="..." target="_top">
<input name="item_name_1" type="hidden" value="<%= Request.Querystring["field"] %>" />
...
<input alt="" src="https://sandbox.google.com/checkout/buttons/buy.gif?merchant_id=..." type="image" />
</form>
然后使用javascript / jquery自动发布此表单onload:
$("form").submit();
这解决了每页只有1个表单的问题。
答案 1 :(得分:1)
添加runat="server"
以在后面的代码中显示该标记。