<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="HiddenFieldTest" %>
HiddenField Test
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class HiddenFieldTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
hfImage1.Value = "0";
hfImage2.Value = "0";
}
}
protected void ibtnImage1_Click(object sender, EventArgs e)
{
IncrementCount(hfImage1);
labMessage1.Text = "# Clicks: " + hfImage1.Value;
}
protected void ibtnImage2_Click(object sender, EventArgs e)
{
IncrementCount(hfImage2);
labMessage2.Text = "# Clicks: " + hfImage2.Value;
}
private void IncrementCount(HiddenField hf)
{
int count = Convert.ToInt32(hf.Value);
count++;
hf.Value = count.ToString();
}
}