ASP.NET hidden field vs. invisible textbox

前端 未结 4 1074
野性不改
野性不改 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:02

    The hidden field generate element on the page, which cannot be seen but the client can get the element, set the data and pass to the server:

    document.getElementById('<%= SomeHiddenField.ClientID %>').value = "data_pass_to_server";
    

    after postback you can get the value:

    var clientData = SomeHiddenField.Value; // "data_pass_to_server"
    

    If you're using invisible textbox (), there's no element generated in the html file.

提交回复
热议问题