简体   繁体   中英

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..
var text = $("#hdID").val(); 

请这样尝试。

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM