Skip to content Skip to sidebar Skip to footer

How Do I Refer To An Html Id In Code?

I have things like:
...
How do I refer to this form in my C# codebehind? I tried simply using 'Form1' but it gives me an error. And googling

Solution 1:

You need to run the form server side:

<form id="Form1" runat="server> ... </form>

However, if you are using ASP.NET Web Forms you can only have 1 form per web form running server side.


EDIT: 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>

Then use javascript/jquery to automatically post this form onload:

$("form").submit();

This gets around the issue of only having 1 form per page.

Solution 2:

Add runat="server" to get that tag visible in codebehind.

Post a Comment for "How Do I Refer To An Html Id In Code?"