[英]How can I get value ID from ascx code behind
I have 3 pics above. 我上面有3张照片。 I don't know how to declare variable in JavaScript to get value from ascx and code behind.
我不知道如何在JavaScript中声明变量以从ascx和背后的代码中获取价值。
ALL CREDIT GOES TO: https://stackoverflow.com/a/5392980/9357872 所有积分都转到: 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. 使用以下代码使用jQuery代码获取隐藏值。
var libraryName = $("input[id$='hdnLibraryName']").val();
Example: 例:
.ascx code .ascx代码
<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 .ascx.cs代码
protected void Page_Load(object sender, EventArgs e)
{
this.hdnLibraryName.Value = "Library1126";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.