I have a basic HTML form that gets inserted into a server side div tag based on how many records exist in the database. This HTML form comes out just fine, and everything looks good. But on my action page I cannot seem to access the input elements from the code behind. I have tried using the Request scope, but I have come up empty on that approach. Any other suggestions?
All of the below suggestions are great, and normally that is what I would do. But these forms are being built on the fly after the page is being compiled, so runat='server' did not do anything for me. It just passed that along to the HTML page.
If you are accessing a plain HTML form, it has to be submitted to the server via a submit button (or via JavaScript post). This usually means that your form definition will look like this (I’m going off of memory – make sure you check the HTML elements are correct):
You should be able to access the customerName and customerPhone data like this:
If you have
method="GET"in the form (not recommended – it messes up your URL space), you will have to access the form data like this:This of course will only work if the form was ‘Posted’, ‘Submitted’, or done via a ‘Postback’ (i.e., somebody clicked the ‘Save’ button, or this was done programmatically via JavaScript).
Also, keep in mind that accessing these elements in this manner can only be done when you are not using server controls (i.e.,
runat="server"). With server controls, the id and name are different.