I want to add a hidden field programmatically to an asp.net page, read and change it via javascript. So far my code fails at reading the added hidden field.
Here is a si
You could try something like this:
protected void Page_Load(object sender, EventArgs e)
{
HtmlInputHidden hidden2 = new HtmlInputHidden();
hidden2.ID = "Here you will put the id of the control";
hidden2.Value = "Here you will put your value";
this.Controls.Add(hidden2);
}
At the top of your source code file, you have to add this statement:
using System.Web.UI.HtmlControls;
The main problem was that the following line was missing in the aspx page:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
The codebehind was never executed.