我在后面的代码中动态生成按钮,并从数据库表中为其分配ID。
Dim subjectLinkButton As LinkButton = New LinkButton()
subjectLinkButton.Attributes.Add("ID", doc.InboxId)
subjectLinkButton.Text = doc.ReceivedSubject
AddHandler subjectLinkButton.Click, AddressOf subjectLinkButton_Click
当我点击按钮时,我用这个
Dim btn As LinkButton = DirectCast(sender, LinkButton)
Me.debugTest.InnerText = "Button ID:" & btn.ID
我收到此错误: 你调用的对象是空的。在Inbox.subjectLinkButton_Click(Object sender,EventArgs e)
答案 0 :(得分:1)
将Attributes.Add更改为
subjectLinkButton.CommandName = "inbox_id"
subjectLinkButton.CommandArgument = doc.InboxId
和
Dim btn As LinkButton = DirectCast(sender, LinkButton)
Me.debugTest.InnerText = "Button: " & btn.CommandName & " " & btn.CommandArgument