Export (0) Print
Expand All

HtmlInputHidden Class

Allows programmatic access to the HTML <input type=hidden> element on the server.

For a list of all members of this type, see HtmlInputHidden Members.

System.Object
   System.Web.UI.Control
      System.Web.UI.HtmlControls.HtmlControl
         System.Web.UI.HtmlControls.HtmlInputControl
            System.Web.UI.HtmlControls.HtmlInputHidden

[Visual Basic]
Public Class HtmlInputHidden
   Inherits HtmlInputControl
   Implements IPostBackDataHandler
[C#]
public class HtmlInputHidden : HtmlInputControl,
   IPostBackDataHandler
[C++]
public __gc class HtmlInputHidden : public HtmlInputControl,
   IPostBackDataHandler
[JScript]
public class HtmlInputHidden extends HtmlInputControl implements
   IPostBackDataHandler

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

You can use the HtmlInputHidden control to embed nonvisible information within a <form> element. This information is sent when the Web page is posted back to the server. The HtmlInputHidden control provides a ServerChange event that is raised when the Value property changes values between posts to the server. This allows you to create an event handler that performs a custom set of instructions each time the event is raised.

Note   The HtmlInputHidden control does not provide a built-in way to post back to the server. You must provide another control on the Web page that supports posting to the server, such as an HtmlButton control, to send the value of the control back to the server.
Note   The Web Forms page framework uses this HTML feature to automatically load and persist the view state of server controls on a page.

For a list of initial property values for an instance of HtmlInputHidden, see the HtmlInputHidden constructor.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use an HtmlInputHidden control to store information on the Web page between posts to the server.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <script language="VB" runat="server">
    Sub Page_Load(sender As Object, e As EventArgs)
        
        If Page.IsPostBack Then
            Span1.InnerHtml = "Hidden value: " & "<b>" & HiddenValue.Value & "</b>"
        End If
    End Sub 'Page_Load


    Sub SubmitBtn_Click(sender As Object, e As EventArgs)
        HiddenValue.Value = StringContents.Value
    End Sub 'SubmitBtn_Click
 </script>

</head>

<body>

   <form runat=server>

      <h3>HtmlInputHidden Sample</h3>

      <input id="HiddenValue" 
             type=hidden 
             value="Initial Value" 
             runat=server>

      Enter a string: 
 
      <input id="StringContents" 
             type=text 
             size=40 
             runat=server>

      <p>

      <input type=submit 
             value="Enter" 
             OnServerClick="SubmitBtn_Click" 
             runat=server>

      <p>

      <span id=Span1 runat=server>
         This label will display the previously entered string.
      </span>

   </form>

</body>
</html>

   

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>

   <script language="C#" runat="server">

      void Page_Load(object sender, EventArgs e) 
      {

         if (Page.IsPostBack) 
         {
            Span1.InnerHtml="Hidden value: <b>" + HiddenValue.Value + "</b>";
         }
      }

      void SubmitBtn_Click(object sender, EventArgs e) 
      {
         HiddenValue.Value=StringContents.Value;
      }

   </script>

</head>

<body>

   <form runat=server>

      <h3>HtmlInputHidden Sample</h3>

      <input id="HiddenValue" 
             type=hidden 
             value="Initial Value" 
             runat=server>

      Enter a string: 
 
      <input id="StringContents" 
             type=text 
             size=40 
             runat=server>

      <p>

      <input type=submit 
             value="Enter" 
             OnServerClick="SubmitBtn_Click" 
             runat=server>

      <p>

      <span id=Span1 runat=server>
         This label will display the previously entered string.
      </span>

   </form>

</body>
</html>

   

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
<head>

   <script language="JSCRIPT" runat="server">
    function Page_Load(sender : Object, e : EventArgs){
        if(Page.IsPostBack)
            Span1.InnerHtml = "Hidden value: " + "<b>" + HiddenValue.Value + "</b>"
    }


    function SubmitBtn_Click(sender : Object, e : EventArgs){
        HiddenValue.Value = StringContents.Value
    }
 </script>

</head>

<body>

   <form runat=server>

      <h3>HtmlInputHidden Sample</h3>

      <input id="HiddenValue" 
             type=hidden 
             value="Initial Value" 
             runat=server>

      Enter a string: 
 
      <input id="StringContents" 
             type=text 
             size=40 
             runat=server>

      <p>

      <input type=submit 
             value="Enter" 
             OnServerClick="SubmitBtn_Click" 
             runat=server>

      <p>

      <span id=Span1 runat=server>
         This label will display the previously entered string.
      </span>

   </form>

</body>
</html>

   

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Web.UI.HtmlControls

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Web (in System.Web.dll)

See Also

HtmlInputHidden Members | System.Web.UI.HtmlControls Namespace | HtmlInputControl

Show:
© 2014 Microsoft