如何我指的是code一个HTML ID? [英] How do I refer to an html id in code?
问题描述
我有这样的话:
<form id="Form1"> ... </form>
我如何参照这种形式在我的C#codebehind?我试图单纯用Form1的,但它给了我一个错误。而谷歌搜索也毫无帮助。
How do I refer to this form in my C# codebehind? I tried simply using "Form1" but it gives me an error. And googling hasn't helped either.
我试图做到的,是输入项目名称,或这些字段之一动态地在谷歌结帐立即购买按钮。请参阅:如何订阅点击HTML表单的事件?一>
What I'm trying to achieve is to enter the item name or one of those fields dynamically on a google checkout "buy now" button. See: How to subscribe to click event of html form?.
推荐答案
您需要运行表单服务器端:
You need to run the form server side:
<form id="Form1" runat="server> ... </form>
不过,如果您使用的是ASP.NET Web窗体只能在运行服务器端的每个Web形式1 Form。
However, if you are using ASP.NET Web Forms you can only have 1 form per web form running server side.
编辑:看到您的编辑后,我会建议使用您的网站上张贴的值,以一个独立的值的Response.Redirect()
:
After seeing your edit, I would recommend posting the values to a standalone value on your website using Response.Redirect()
:
Response.Redirect("GoogleCheckout.aspx?field=" + fieldvalue);
那么这个独立的页面上有以下几点:
Then on this standalone page have the following:
<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:
Then use javascript/jquery to automatically post this form onload:
$("form").submit();
这得到周围每页只能有1形式的问题。
This gets around the issue of only having 1 form per page.
这篇关于如何我指的是code一个HTML ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!