MRWonderFuXker
MRWonderFuXker

Reputation: 203

how can I get the value from a HiddenField which created in program?

I want to get the value of the HiddenField in asp. However, the question is that HiddenField is created in program which is not from asp control.

     protected override void OnInit(EventArgs e)
    {
        hd = new HiddenField();
        hd.ID = "hdID"
        hd.Value = jsonString;

        this.Controls.Add(hd);

       //........

        base.OnInit(e);
        InitializeControl();
    }

Then when I trying to read its value..

var text = $("#<%=hdID.ClientID%>").val(); // fail, it says that the hd is not exist..

Upvotes: 1

Views: 48

Answers (2)

Vikrant
Vikrant

Reputation: 5036

Try this:

$(document).ready(function () {
    var text = $("#<%=hdID.ClientID%>").val();
}

Upvotes: 0

Jhacc
Jhacc

Reputation: 21

var text = $("#hdID").val(); 

please try it like this.

Upvotes: 2

Related Questions