正如问题所示,我遇到了一个愚蠢的问题,失败的代码如下所示:
<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
最佳答案
document.getElementById('HiddenField1').value = parent;
这不是HiddenField1
的HTML。因此,您应该通过ClientID
引用它。document.getElementById('<%=HiddenField1.ClientID %>').value= parent;
关于javascript - JavaScript将按钮ID传递给asp.net隐藏字段,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31051307/