Reputation:
I am generating button dynamically in the code behind and assign ID to it from a database table.
Dim subjectLinkButton As LinkButton = New LinkButton()
subjectLinkButton.Attributes.Add("ID", doc.InboxId)
subjectLinkButton.Text = doc.ReceivedSubject
AddHandler subjectLinkButton.Click, AddressOf subjectLinkButton_Click
When I click on the button, I use this
Dim btn As LinkButton = DirectCast(sender, LinkButton)
Me.debugTest.InnerText = "Button ID:" & btn.ID
I get this error: Object reference not set to an instance of an object. at Inbox.subjectLinkButton_Click(Object sender, EventArgs e)
Upvotes: 0
Views: 410
Reputation:
Changed Attributes.Add to
subjectLinkButton.CommandName = "inbox_id"
subjectLinkButton.CommandArgument = doc.InboxId
and
Dim btn As LinkButton = DirectCast(sender, LinkButton)
Me.debugTest.InnerText = "Button: " & btn.CommandName & " " & btn.CommandArgument
Upvotes: 1