471,049 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,049 software developers and data experts.

Multiple user controls on the same page

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!

Jul 5 '06 #1
2 2511
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

Jul 5 '06 #2

Leon Mayne wrote:
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
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!

Jul 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Damon | last post: by
1 post views Thread by MichaƂ Januszczyk | last post: by
2 posts views Thread by ScottOnes | last post: by
3 posts views Thread by Nathan Sokalski | last post: by
1 post views Thread by SteveComplex | last post: by
11 posts views Thread by Ranginald | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.