简体   繁体   English

我怎样才能从ascx代码后面获取值ID

[英]How can I get value ID from ascx code behind

后面的ascx代码

ascx

javascript文件

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.

相关问题 如何从后面的代码中获取ID传递给javascript函数的控件的值 - How can I get the value of a control whose ID was passed to javascript function from code behind 页面后面的ASCX.cs代码未从ascx页面提取值 - ASCX.cs code behind page not pulling value from the ascx page 我可以像这样将$(“#id”)。html()这样的html值发送给后面的代码吗? - Can I send the value of html like this $(“#id”).html() to code behind? 如果ImageButton是在后面的代码中创建的,如何获取javascript的ImageButton的ID? - How can I get the ID of ImageButton for javascript, if the ImageButton was created in code behind? 如何使用C#从ascx代码后面调用javascript函数 - how to call javascript function from ascx code behind using C# 我如何从javascript中获取名称以跟随以下代码 - how can i get name from javascript to code behind from following 从不同的代码隐藏更改ascx内容 - Changing a ascx content from different code-behind 从文件后面的ASCII代码调用Aspx Java脚本函数 - Call Aspx java script function from ascx code behind file 从ascx页面代码后面调用Javascript函数 - call a Javascript function from ascx page code behind 我怎样才能得到这个输入 id 值的这个值(这个值是通过 ID 从其他输入值加载的) - how can i get this value of this input id value (this value was loaded from other input value by ID )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM