Hidden fields - DotNet and DataBase

Thursday, 9 August 2018

Hidden fields



Hidden fields are the server side and nonvisual controls in ASP.NET where you can save the value.  Hidden field is one of the types of client-side state management technique and it retains the values between the postback events.

By selecting the browser view source (control+U) we can see the hidden field value. So, it is not safe to preserve the sensitive information like passwords on the hidden fields.


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


aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Welcome.aspx.cs" Inherits="WebProgramming.Welcome" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            &nbsp;<table>
                <tr><td colspan="2">
                    <asp:HiddenField ID="hdfValue" runat="server"/>

                    </td></tr>
            <tr>
                <td>
                    <asp:Label ID="lblOne" runat="server" Text="Increment" Font-Size="XX-Large"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" Height="42px" Width="298px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblTwo" runat="server" Text="Copy from Increment" Font-Size="XX-Large"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server" AutoPostBack="True" Height="49px" Width="302px" EnableViewState="true"></asp:TextBox>
                </td>
            </tr>
             <tr>
                <td style="text-align:right">
                   <asp:Button ID="Button1" runat="server" Height="43px" OnClick="Button1_Click" Text="Submit" Width="90px" />
                    </td>
                     <td style="text-align:right">
                   <asp:Button ID="Button2" runat="server" Height="43px" OnClick="Button2_Click" Text="Submit2" Width="90px" />
                    </td>
            </tr>
        </table>

        </div>
       
    </form>
</body>

</html>


Code Behind
protected void Page_Load(object sender, EventArgs e)
        {
            hdfValue.Value = "xyz";

        }

Hidden field in the View source page:



No comments:

Post a Comment

x

Get Updates On

Discussion updates

Straight Into Your INBOX!

Enter your email address to subscribe to this website and receive notifications of new posts by email.