.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
sritaa
Sandeep Singh
Melody Anderson
Sharad
Eminent IT

  

Hidden Field Control

   
 
     


Introduction :

Hidden Field as the name suggests, it will be hidden to the user that means you can store some value but user can not able to see that value in a webpage. But you should not keep any sensitive information in hidden field because it is available in a webpage, but user cannot see it directly. You can see the hidden field value by right click on a web page and go to "View Source". There you can see the hidden field value along with html tag available in a web page, so it is not secure.

Hidden Field as the name suggests, it will be hidden to the user. That means you can store some value but user can not be able to see that value in a webpage. But you should not keep any sensitive information in hidden field because it is available in a webpage. You can see the hidden field value by right click on a web page and go to "View Source". There you can see the hidden field value along with html tag available in a web page, so it is not secure.


So where Hidden field is required?


Hidden field is required when you want to pass some value to the client and process its value using some scripting language (eg. Java Script,  Vb Script) without showing to the user.


How does hidden field tag look like in your Web Page(.aspx)?

<asp:HiddenField ID="myHiddenField" runat="server" />


Full Html code used in sample application:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Hiddenfield Examlple - www.DotNetSpark.com</title>

    <script language="javascript" type="text/javascript">

    function myJavaScriptFunction()

    {

      

        var hiddenFieldRef = document.getElementById(''<%= myHiddenField.ClientID %>'');

        alert(hiddenFieldRef.value);

      

    }

    </script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

   

        <asp:Label ID="lblPageMessage" runat="server" Text="Hidden Field Example"></asp:Label>

        <br />

        <br />

     <br />

        <table style="width:100%;">

            <tr>

                <td>

                    &nbsp;</td>

                <td>

                    &nbsp;</td>

            

            </tr>

            <tr>

                <td>

      

                <input type="button"  onblur="myJavaScriptFunction()" value="Click Me" />

                </td>

                <td>

                    &nbsp;</td>

              

            </tr>

            <tr>

                <td>

        <asp:HiddenField ID="myHiddenField" runat="server" />

     <asp:Label ID="lblEnteredVal" runat="server"></asp:Label>

                </td>

                <td>

                    &nbsp;</td>

              

            </tr>

        </table>

    </div>

    </form>

</body>

</html>

And server side code are

    protected void Page_Load(object sender, EventArgs e)

    {

        myHiddenField.Value = "Hello From Server";

    }

Other Tutorials in the same Category:
      
  • CheckBoxList Control      
  • Button Control      
  • Calendar Control      
  • CheckBox Control      
  • DropDownList Control or Combobox      
  • FileUpload Control      
  • Hidden Field Control      
  • ImageButton Control      
  • Link Button Control      
  • ListBox Control      
  • Literal Control      
  • RadioButton Control      
  • RadioButtonList Control      
  • TextBox Control

  •  
         
     
    Return to Main Index Page


    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend