473,379 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Server altering name of form fields

CJM
[A third attempt - my first two attempts doesn't appear to have shown
up -yet]

I have a bit of code that inserts some extra controls (specifically,
ordinary <input type="hidden" name="MyField"form fields) into an existing
HTML form. However, it is mangling the name & IDs of these controls when
they are rendered:

For example, the PPItemName field is rendered as: <input
name="ctl00$MainBodyContent$PPItemName" type="hidden"
id="ctl00_MainBodyContent_PPItemName" />

Ordinarily, I wouldn't care (and it wouldn't matter either), but this form
is posting to a Paypal server and paypal is expecting particular field
names - so consequently we are having problems.

I can understand that .NET needs to use the ID attribute, but why the name
attribute? The name attribute is important in standard HTML, but I wouldn't
have thought so for .NET.

A workaround would be to use a placeholder, and use .innerHTML to inject
straight HTML inside. But this entire piece of code is already a workaround
for .NETs inability to handle multiple forms, so I thought there must be a
limit to the amount of messing about that I have to do.

Is there a way that I can force the server not to change the name of the
fields?

Thanks in advance...

Chris

Sep 23 '08 #1
11 1860
"CJM" <cj*****@removeme-yahoo.co.ukwrote in message
news:6j************@mid.individual.net...
I have a bit of code that inserts some extra controls (specifically,
ordinary <input type="hidden" name="MyField"form fields) into an
existing
HTML form. However, it is mangling the name & IDs of these controls when
they are rendered:
Correct. That is standard behaviour.
Is there a way that I can force the server not to change the name of the
fields?
Absolutely not! Don't even try - you'll almost certainly break your app if
you do.
Ordinarily, I wouldn't care (and it wouldn't matter either), but this form
is posting to a Paypal server and PayPal is expecting particular field
names - so consequently we are having problems.
Ah yes - a familiar problem...
A workaround would be to use a placeholder, and use .innerHTML to inject
straight HTML inside. But this entire piece of code is already a
workaround
for .NETs inability to handle multiple forms, so I thought there must be a
limit to the amount of messing about that I have to do.
Regrettably, I don't know any other way of doing what you're trying to do so
long as you continue to use form submission.

Obviously, form submission isn't the *only* way to interface with PayPal...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 23 '08 #2
CJM

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:eh**************@TK2MSFTNGP05.phx.gbl...
>
Correct. That is standard behaviour.
Agreed - I just wasn't sure whether 'standard' meant 'only' behaviour. It
does.
>Is there a way that I can force the server not to change the name of the
fields?

Absolutely not! Don't even try - you'll almost certainly break your app if
you do.
Any more than a succession of workarounds?

It's frustrating that, while .NET is leagues ahead of Classic ASP in almost
every other area, it still manages to shoot itself in the foot in this way.
>
Obviously, form submission isn't the *only* way to interface with
PayPal...
No, but it is the simplest and easiest, especially for the way in which I am
using it. I will be looking into the other APIs and mechanisms in good time,
but in the short term I will persist with this.

It's not the end of the world, but it's a shame.

C'est la vie!

Thanks

Chris

Sep 23 '08 #3
"CJM" <cj*****@removeme-yahoo.co.ukwrote in message
news:6j************@mid.individual.net...
>>Is there a way that I can force the server not to change the name of the
fields?

Absolutely not! Don't even try - you'll almost certainly break your app
if you do.

Any more than a succession of workarounds?
A workaround isn't supposed to break your app, not even a succession of
them...
It's frustrating that, while .NET is leagues ahead of Classic ASP in
almost every other area, it still manages to shoot itself in the foot in
this way.
The munging of control identifiers is necessary to allow things like
nesting, MasterPages and other UserControls to co-exist etc...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 23 '08 #4
CJM

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ur**************@TK2MSFTNGP03.phx.gbl...
>>
Any more than a succession of workarounds?

A workaround isn't supposed to break your app, not even a succession of
them...
Every bit on 'unneccessary' code makes it harder to maintain and makes bugs
more likely - as well as making development more of a chore.

In this case, the working solution is only slightly more clumsy than my
first attempted method, but it's the principle that I feel like I'm fighting
*against* the system rather than working *with* it.

Still, it's been an education - which is half of the objective.

>
The munging of control identifiers is necessary to allow things like
nesting, MasterPages and other UserControls to co-exist etc...
I realise that; but couldnt there be some sort of override? It's a very
useful feature in general, but in this case, I'd rather be allowed to trust
my own naming judgements.

Sep 23 '08 #5
On Sep 23, 4:07*am, "CJM" <cjmn...@removeme-yahoo.co.ukwrote:
I have a bit of code that inserts some extra controls (specifically,
ordinary <input type="hidden" name="MyField"form fields) into an existing
HTML form. However, it is mangling the name & IDs of these controls when
they are rendered:

For example, the PPItemName field is rendered as: <input
name="ctl00$MainBodyContent$PPItemName" type="hidden"
id="ctl00_MainBodyContent_PPItemName" />
<snip>
I can understand that .NET needs to use the ID attribute, but why the name
attribute? The name attribute is important in standard HTML, but I wouldn't
have thought so for .NET.

A workaround would be to use a placeholder, and use .innerHTML to inject
straight HTML inside. But this entire piece of code is already a workaround
for .NETs inability to handle multiple forms, so I thought there must be a
limit to the amount of messing about that I have to do.

Is there a way that I can force the server not to change the name of the
fields?
Hi. Have you tried something like ...

HtmlGenericControl hid = new HtmlGenericControl("input");
hid.Attributes.Add("type", "hidden");
hid.Attributes.Add("id", "MyField");
hid.Attributes.Add("name", "MyField");
this.Form.Controls.Add(hid);

Even in a content page, for example, the input tag renders in the form
without any ID or name mangling:

<input type="hidden" id="MyField" name="MyField"></input>

--
Ben
http://allben.net/
Sep 23 '08 #6
CJM

"Ben Amada" <be*******@gmail.comwrote in message
news:99**********************************@a2g2000p rm.googlegroups.com...
On Sep 23, 4:07 am, "CJM" <cjmn...@removeme-yahoo.co.ukwrote:
Hi. Have you tried something like ...

HtmlGenericControl hid = new HtmlGenericControl("input");
hid.Attributes.Add("type", "hidden");
hid.Attributes.Add("id", "MyField");
hid.Attributes.Add("name", "MyField");
this.Form.Controls.Add(hid);

Even in a content page, for example, the input tag renders in the form
without any ID or name mangling:

<input type="hidden" id="MyField" name="MyField"></input>
Thanks Ben, I'll look into this...

My current code is:

Dim oItemName As New HtmlInputHidden With _
{.ID = "PPItemName", _
.Name = "item_name", _
.Value = Me.EventName.Value & " [" & Me.Location.Value & " - " &
Me.EventDate.Value & "]"}
Me.divPPDetails.Controls.Add(oItemName)

I'm curious as to why a HTMLGenericControl would work OK, but not an
HTMLInputHidden.... Any ideas?

Chris

Sep 24 '08 #7
CJM
This works great, Ben. but why?

Thanks anyway.

Chris
Sep 24 '08 #8
CJM wrote:
This works great, Ben. but why?
Glad to hear that works. Off hand, I don't know the exact reason why the
ID/name is changed for HtmlInputHidden.

HtmlInputHidden along with its siblings (HtmlInputText, HtmlInputButton etc)
are form controls that would typically be included in postback data.
ASP.NET may need to be able to uniquely identify each form control by its
ID. Whereas the value in a HtmlGenericControl is not passed back to the
server in the form's post data. So it is probably not necessary for it to
have a unique ID.

Sep 24 '08 #9
Ben Amada wrote:
Whereas the value in a HtmlGenericControl is not passed back to the
server in the form's post data. So it is probably not necessary for it
to have a unique ID.
Actually, when the tag name for the HtmlGenericControl is a form control
tag, like <input>, the value is passed back to the server in a form post.
If you were to have multiple HtmlGenericControl "input" controls with the
same ID, the browser will send each piece of data to the server with the
same ID (I just checked). So you would want to avoid that situation. I
guess ASP.NET lets you manage HtmlGenericControl elements on your own :-)

Sep 24 '08 #10
On Sep 24, 7:35*am, "CJM" <cjmn...@removeme-yahoo.co.ukwrote:
This works great, Ben. but why?
It appears that there's a difference if you set the
HtmlGenericControl's ID property directly, as opposed to giving it an
ID through the attributes collection.

HtmlGenericControl hgc = new HtmlGenericControl("input");
hgc.ID = "hgc";
hgc.Attributes.Add("name", "hgc");
hgc.Attributes.Add("type", "hidden");
hgc.Attributes.Add("value", "some value");
this.Form.Controls.Add(hgc);

This results in an altered server ID:

<input id="ctl00_hgc" name="hgc" type="hidden" value="some value"></
input>

If you try to omit setting the ID property with the HtmlInputHidden
and instead set it via the attributes collection,

HtmlInputHidden hih = new HtmlInputHidden();
hih.Attributes.Add("id", "hih");
hih.Attributes.Add("name", "hih");
hih.Attributes.Add("type", "hidden");
hih.Attributes.Add("value", "some value");
this.Form.Controls.Add(hih);

Unsuccessfully, you get:

<input name="ctl00$ctl02" type="hidden" id="hih" value="some value"/>

So, best combination is what you already have.
Sep 25 '08 #11
CJM
It's all very curious... but, what-the-hell... it's working & my code isn't
a complete mess so I'm happy.

Thanks again for your thorough efforts on my behalf.

Chris

Sep 25 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side...
1
by: ij | last post by:
Hi, I'm trying to submit an image object, along with some other text fields to another web server from within an ASP page but am stuck on getting the image to be submitted with the form. In a...
26
by: David W. Fenton | last post by:
A client is panicking about their large Access application, which has been running smoothly with 100s of thousands of records for quite some time. They have a big project in the next year that will...
2
by: Francois | last post by:
Hi, I have a form which contains some non server side controls. I have seen in the generated HTML of a page that non server side controls can be read by the server code (C# or VB.NET) as the...
7
by: Donald Grove | last post by:
Is it possible to retrieve field properties from a table in access2000 using code? I have tried: " dim dbs as dao.database dim tbl as dao.tabledef dim fld as dao.field dim prop as...
22
by: Mr Newbie | last post by:
I was thinking about developing a workflow application yesterday and was musing over the different approaches than one could take in restricting specific actions on a ticket( Form ) at any said...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
9
by: JimmyKoolPantz | last post by:
IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. ...
3
by: graphicssl | last post by:
Okay, so first of all, I'm a designer first and a light coder second (I'm only really trained with HTML and CSS). So I apologize for having to post about something that's probably super-trivial! ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.