Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Strange behavior on Posting hidden input fields

I can't always reproduce this bug, but maybe someone has experienced something similar...

I have javascript on my page which sets the value of a hidden input field and then submits the page back to .NET server.

For debugging purposes, I include an alert statement in the javascript before executing "theForm.submit()" in which I display the value of the hidden input field.

For some strange reason, under certain circumstances, which I haven't yet been able to identify, sometimes the actual value gets a comma appended to the beginning of it.

For example:

user clicks on image that calls mySubmit('doSomething')

then...

function mySubmit(cmdName)
{
...
theForm.cmd.value = cmdName;
alert(cmdName); // displays value I expect
theForm.submit();
}

then in VS.NET

...
Page_Load ()
{
....
myVar = Request.Form["cmd"].ToString().Trim();
// sometimes myVar = ",doSomething"
// instead of just "doSomething"
...
}

Thanks

Charles Reich
Wednesday, June 18, 2003

Hi,

You could have several controls on the page with the same name. When this happens the values sent to the server get comma delimited which would explain what you are seeing.

I'd recomment checking the source of the page once it gets to the browser in case .NET has decided to do something fruity.

Thats my best guess anyway

col

Colin
Thursday, June 19, 2003

Thans Colin.  I thought I checked my HTML for duplicate names, but I'll double check.

Charles Reich
Friday, June 20, 2003

Double checked and finally found a duplicate hidden input with the same name attribute.

Thanks for pointing me in the right direction.

Charles Reich
Wednesday, June 25, 2003

*  Recent Topics

*  Fog Creek Home