正如问题所述,我遇到了一个愚蠢的问题,失败的代码如下所示:
<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 .So you should reference it by its ClientID
document.getElementById('<%=HiddenField1.ClientID %>').value= parent;
关于JavaScript 将按钮 ID 传递给 asp.net 隐藏字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31051307/