Creating a hidden field in codebehind and accessing it via clientside javascript

前端 未结 2 1166
陌清茗
陌清茗 2021-01-24 07:24

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

2条回答
  •  猫巷女王i
    2021-01-24 07:54

    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;
    

提交回复
热议问题