简体   繁体   中英

ASPX site can't detect form fields filled in by JavaScript

I'm working 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?

您在输入字段上定义了runat =“ server”属性吗?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM