H
Harry Haller
I want to duplicate the form data, edit it to remove some items (such
as __EVENTTARGET, __EVENTVALIDATION, etc) and save it to a log.
How can I make a duplicate (editable) copy of the Form Collection?
The Form Collection is of type NameValueCollection is, underneath the
covers, an object of type HttpValueCollection.
The problem I have is that my copies have only one key item for a list
(such as a radio button list) whereas the Form has one key per item in
the collection (duplicate keys).
Apart from doing something like:
string aCopy = myForm.ToString();
and then rebuilding the NameValueCollection how can I make an editable
duplicate with duplicate keys for lists?
myForm is passed into a method so:
public void TheHeader(NameValueCollection myForm)
{
...
the calling code is:
SomeClass.TheHeader(Request.Form);
When this happens the resulting myForm is read only.
The code within TheHeader could be:
NameValueCollection nvc = new NameValueCollection();
foreach (string key in myForm)
nvc.Add(key, myForm[key]);
or below which duplicates the above (using the 1st contructor of the
Add method rather than 2nd):
NameValueCollection nvc = new NameValueCollection();
nvc.Add(Request.Form)
No matter how the Form is copied the copy isn't the same because the
original Form has a separate key for each item in a collection (such
as a radio button list). The copy (nvc) will contain only one key
followed by a comma separated value list.
If I serialise it to a string and then use split to put it into an
array how can I be sure that the viewstate and other asp.net fields
won't this up by using the special characters & = , used to delimit
the keys and data?
as __EVENTTARGET, __EVENTVALIDATION, etc) and save it to a log.
How can I make a duplicate (editable) copy of the Form Collection?
The Form Collection is of type NameValueCollection is, underneath the
covers, an object of type HttpValueCollection.
The problem I have is that my copies have only one key item for a list
(such as a radio button list) whereas the Form has one key per item in
the collection (duplicate keys).
Apart from doing something like:
string aCopy = myForm.ToString();
and then rebuilding the NameValueCollection how can I make an editable
duplicate with duplicate keys for lists?
myForm is passed into a method so:
public void TheHeader(NameValueCollection myForm)
{
...
the calling code is:
SomeClass.TheHeader(Request.Form);
When this happens the resulting myForm is read only.
The code within TheHeader could be:
NameValueCollection nvc = new NameValueCollection();
foreach (string key in myForm)
nvc.Add(key, myForm[key]);
or below which duplicates the above (using the 1st contructor of the
Add method rather than 2nd):
NameValueCollection nvc = new NameValueCollection();
nvc.Add(Request.Form)
No matter how the Form is copied the copy isn't the same because the
original Form has a separate key for each item in a collection (such
as a radio button list). The copy (nvc) will contain only one key
followed by a comma separated value list.
If I serialise it to a string and then use split to put it into an
array how can I be sure that the viewstate and other asp.net fields
won't this up by using the special characters & = , used to delimit
the keys and data?