ASP.NET hidden field vs. invisible textbox

前端 未结 4 1076
野性不改
野性不改 2021-02-20 03:16

what are benefits of using a hidden field in ASP.NET when we can use another invisible element such as label or text box?

4条回答
  •  感动是毒
    2021-02-20 04:04

    A hidden field renders as input type="hidden" in the resulting HTML. Being an input the value in the input is submitted to the server on postback while this is not the case with a label. Depending on whether or not you want that value submitted to the server you should use input or label. If you don't want the value to be submitted then label is the right solution and hidden field is wrong.

    I am not sure what you mean by invisible textbox but if you are trying to make it invisible via CSS keep in mind that the input type has semantic meaning to search engines, bots, etc. Also at some point your HTML might be served without CSS or with different CSS and the text box will become visible to the user. Otherwise there are no differences between hidden field and invisible text box as both of them render inputs.

提交回复
热议问题