ASPX site can't detect form fields filled in by JavaScript
I'm worki开发者_如何学编程ng on a web application in ASP.NET/C#, which involves asking users to input data. My client has requested the addition of a JavaScript utility that allows the user to enter a postcode, and have all other address fields be automatically filled in for them. When we test the application, the JavaScript appears to fill in the address fields correctly but the C# validation code reports them to be empty. I've tried googling several different combinations of terms but haven't found anything useful. How do I get this to work?
Do you have the runat="server" attribute defined on your input fields?
Are the fields disabled? Disabled fields will not be posted by the browser, so .NET will not know about them. If that's the case, simply make copies in type="hidden"
input fields, which will be posted.
You have to read them by name from Request.Forms
though, if I remember correctly.
Set EnableClientScript="false" on the validators, that will run the validation from the server, instead of the client side? I'm just making a guess here.
Does it work if you hand-type the values?
I ask becuase not so long ago I spent way too much time debugging a similar problem and it happened that my initialize-fields code was running on every postback essentially clearing anything that came in on the request.
If you hand-type the values and it still complains about empty fields, that might be the problem.
精彩评论