Input fields are renamed with runat="server", how do I change it

J

jamessmb

Hello,

I have a webform which needs to post to PayPal. One of the elements is a
hidden field which I am populating with a value from the URL. In order to do
this, I have to use runat="server'. But when I do, ASP.NET will rename the
field. The field needs to be named "custom" so PayPal will know what to do
with it.

How can I prevent this, or what can I do?
Thanks,
James
 
J

jamessmb

Hi,

I'm using version 2

create an input field like this:
<input type="hidden" id="custom" name="custom" value="" runat="server" />

What is rendered is this:

<input name="ctl00$ctl00$SiteContentPlaceHolder$CenterColumn$custom"
type="hidden" id="ctl00_ctl00_SiteContentPlaceHolder_CenterColumn_custom" />

I actually did find a workaround with Javascript, since the "custom"
variable is passed in the query string to this page:

var uName = document.location.search;
var uNameArr = uName.split("=");
document.getElementById('custom').value = uNameArr[1];

However, I still would like to know how to deal with this. It seems to me
there should be a way to keep the name.

Thanks,
James
 
K

Keith Patrick

You could subclass HtmlInputHidden (or whatever that thing is called;
there's 2 similarly-named ones, and I can never remember which is which) and
override ClientID and UniqueID, but that behavior is otherwise by design, as
it needs to prepend the control tree before the name/ID so that two
identically-named fields (gets common with user controls) don't "collide"
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top