Hello,
I have a a web form where i dynamically load a user control. The web
page is an issue log, and each user control I add is a specific issue.
I load them as follows:
Try
sqlConn.Open()
With sqlCmd
.CommandType = CommandType.StoredProcedure
.CommandText = "sp_s_Issues"
.Parameters.Add(New
SqlClient.SqlParameter("@ClientTaskID", CType(Page,
DMSPageBase).Task.ClientTaskID))
.Connection = sqlConn
End With
sqlAdapter.SelectCommand = sqlCmd
sqlAdapter.Fill(sqlSet)
x = 1
For Each row In sqlSet.Tables(0).Rows
ILD = LoadControl("issuelog_detail.ascx")
ILD.sqlConn = sqlConn
ILD.LoadIssueData(row)
ILD.ID = "IssueLog_" & x
pnlIssues.Controls.Add(ILD)
x = x + 1
Next
Finally
sqlConn.Close()
End Try
This works great. All the issue log detail show up. The user control
has a button which allows someone to add a comment about the issue.
This works fine on the first control. The comment gets added no
problem. If I try to add a comment to the second user control, the
comment actually gets added to the first user control (the comment gets
added to the database with the ID of the first issue control). I
checked each command button and they do have different IDs:
_ctl1_IssueLog_1_cmdAddComment
_ctl1_IssueLog_2_cmdAddComment
_ctl1_IssueLog_3_cmdAddComment
The problem is that the event handler is messing up. If I press the
second command button, the event for the first command button fires.
When I debug, if I press the second button, I have a break point in the
command button handler. When it breaks I look at the issue ID and it's
the ID of the first issue, not the second. The event handler always
seems to be calling the first user controls procedure.....
Can comeone please help? Thanks!