forms can not be nested, so the placeholder must be outside the form.
you could create you own naming container, that did not munge the names or
better yet create a pay pal control, that render the form and the hidden
fields.
pretty trival:
public class paypal : WebControl
{
public string Field1 { get; set; }
public string Field2 { get; set; }
protected override HtmlTextWriterTag TagKey
{
get { return HtmlTextWriterTag.Form; }
}
public override void RenderBeginTag(HtmlTextWriter writer)
{
writer.AddAttribute("action", "https://someurl");
writer.AddAttribute("method", "post");
base.RenderBeginTag(writer);
}
protected override void RenderChildren(HtmlTextWriter writer)
{
renderHidden(writer, "field1", Field1);
renderHidden(writer, "field2", Field1);
}
private void renderHidden(HtmlTextWriter writer, string name, string
value)
{
writer.AddAttribute("type", "hidden");
writer.AddAttribute("name", name);
writer.AddAttribute("value", HttpUtility.HtmlEncode(value));
writer.RenderBeginTag("input");
writer.RenderEndTag();
}
}
-- bruce (sqlwork.com)
"CJM" wrote:
[A second attempt - my first attempt 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