Multiple user controls on the same page

M

mikeingenito

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!
 
G

Guest

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

Does it work if you use:

For Each row In sqlSet.Tables(0).Rows
Dim ILD as new issuelog_detail() ' Or whatever your control's class is
called
 
M

mikeingenito

Leon said:
Does it work if you use:

For Each row In sqlSet.Tables(0).Rows
Dim ILD as new issuelog_detail() ' Or whatever your control's class is
called

For some reason, when I use NEW the usercontrols do not display. It is
very strange. I also tried using LoadTemplate to no avail. Please
help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top