problem using hidden field in aspx webpage!

J

Jeff

hi

asp.net 3.5

I'm trying to integrate a paypal button to my webpage. On my webpage I have
a list of hidden fields which have parameters which will be sent back to
PayPal when user clicks on the image:
<input type="hidden" name="t3" value="M">
<input type="hidden" name="sra" value="1">

PROBLEM
One of the hidden fields I need to set during runtime, This hidden field
should contain username. PayPal require this hidden field to be named
"custom", but during runtime I notice that my hidden field has a different
name despite I named it "custom":
The name I see in the html source is
"ctl00$ContentPlaceHolder1$cuwNewUser$__CustomNav1$custom"

In the markup I created this hidden field this way:
<input type="hidden" name="custom" runat="server" id="custom" />

In the code I reference the hidden field this way:
HtmlInputHidden hidden =
(HtmlInputHidden)TempStep.CustomNavigationTemplateContainer.FindControl("custom");
(it happens inside a create user wizard)

What am I doing wrong here?
 
L

Leon

hi

asp.net 3.5

I'm trying to integrate a paypal button to my webpage. On my webpage I have
a list of hidden fields which have parameters which will be sent back to
PayPal when user clicks on the image:
<input type="hidden" name="t3" value="M">
<input type="hidden" name="sra" value="1">

PROBLEM
One of the hidden fields I need to set during runtime, This hidden field
should contain username. PayPal require this hidden field to be named
"custom", but during runtime I notice that my hidden field has a different
name despite I named it "custom":
The name I see in the html source is
"ctl00$ContentPlaceHolder1$cuwNewUser$__CustomNav1$custom"

In the markup I created this hidden field this way:
<input type="hidden" name="custom" runat="server" id="custom" />

In the code I reference the hidden field this way:
HtmlInputHidden hidden =
(HtmlInputHidden)TempStep.CustomNavigationTemplateContainer.FindControl("custom");
(it happens inside a create user wizard)

What am I doing wrong here?

The clientID for the server-side controls are being created (generated
one might say) by the framework; these names can not be changed.
What you could do is fumble around with JavaScript (although I
personally wouldn't recommend it - due to browser versions and other
problems).

Workaround #1

What you could do (as a workaround) is put your hidden fields inside a
DataRepeater, bind a datatable (with just that one row) to the
repeater and use something like this

<input type="hidden" value='<%# Eval("CustomFieldName") %>'
id="custom">

(mark the usage of ' and " in the value)

Workaround #2

Create a panel surounding (or inside) your "POST" form (and don't set
visible=false but set size to 1,1 or something) and add a
literalcontrol to that control like

{panel}.Control.Add(new LiteralControl("<input type....

..L.
 
C

Coskun Sunali [MVP]

Indeed with everything that Leon mentioned. Just one news, in ASP.NET 4.0,
you will be able to set the ClientID property to whatever you wish.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top