


I have 3 pics above. I don't know how to declare variable in JavaScript to get value from ascx and code behind.



I have 3 pics above. I don't know how to declare variable in JavaScript to get value from ascx and code behind.
ALL CREDIT GOES TO: https://stackoverflow.com/a/5392980/9357872
Add a class then get the value of the class:
<input type="hidden" id="hdnLibraryName" runat="server" CssClass="library"/>
Then:
var LibraryName = $(".library").val();
Using the code as below to get the hidden value using jQuery code.
var libraryName = $("input[id$='hdnLibraryName']").val();
Example:
.ascx code
<input type="hidden" id="hdnLibraryName" runat="server"/>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        var libraryName = $("input[id$='hdnLibraryName']").val();
        console.log(libraryName);
    });
</script> 
.ascx.cs code
protected void Page_Load(object sender, EventArgs e)
{
    this.hdnLibraryName.Value = "Library1126";
}