【问题标题】:JavaScript Pass button id to an asp.net hiddenfieldJavaScript 将按钮 ID 传递给 asp.net 隐藏字段
【发布时间】:2015-09-12 02:47:54
【问题描述】:

正如问题所述,我遇到了一个愚蠢的问题,失败的代码如下所示:

<script type="text/javascript">
    function HISenlarge(id) {
    var parent = id;
    document.getElementById('HiddenField1').value = parent;
 }
</script>

HTML:

<button type="button"  id="kkkk" onclick="HISenlarge(this.id)"></button>
<asp:HiddenField ID="HiddenField1" runat="server" value=""/>

VB代码

 Protected Sub CommentButton_Click(sender As Object, e As EventArgs) Handles CommentButton.Click
    Dim c_id As String
    c_id = HiddenField1.Value.ToString

【问题讨论】:

  • 你遇到了什么错误?
  • hiddenField 里面什么都没有
  • 您是否检查过您在 HISenlarge 函数中获得的“id”值?
  • document.getElementById('&lt;%=HiddenField1.ClientID %&gt;').value= parent; ?
  • 工作感谢 Nagaraj S

标签: javascript html asp.net vb.net


【解决方案1】:

document.getElementById('HiddenField1').value = parent;

这不是 HiddenField1 的 HTML。所以你应该通过它的 ClientID 来引用它

document.getElementById('&lt;%=HiddenField1.ClientID %&gt;').value= parent;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-04
    • 2023-03-26
    • 2022-01-10
    • 2011-01-10
    • 1970-01-01
    • 2014-08-14
    相关资源
    最近更新 更多