473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Display UserControl declared in another Class

Hello,

i'm new to .Net (i'm using VB as language and i'm working in the
code-behind mode) and i can't solve the following problem:
I have a WebForm and want to Add a UserControl
(classname:QuestionControl) as many times as there are rows in a
DataTable (also named Questions) in a DataSet. But this UserControl is
,for reasons of structuring, not a member of the WebForm Object in
which it should be displayed, it is member of another class
(classname:question) along with other Information and forms a logical
unit.
So i'm creating an object of that QuestionControl in the
question-class and add it to a Placeholder in the Webform with
"Me.PlaceHolder1.Controls.Add(QuestionObj.Question ControlObj)". But
nothing appears on the WebForm.
I've tried it for test-purposes with a Label-Control instead of the
UserControl and that works fine.

Here is a part of the source:

[WebForm1.aspx.vb]
....
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

Dim QuestionObj As Question
Dim QuestionRow As Dataset2.QuestionRow
Dim QC As New QuestionControl
QuestionCollection = New QuestionCollection 'A simple
collection for the Question-Class-Objects
For Each QuestionRow In Dataset1.Question
QuestionObj = New Question(QuestionRow)
QuestionCollection.Add(QuestionObj)
Next
For Each QuestionObj In QuestionCollection

Me.PlaceHolder1.Controls.Add(QuestionObj.QuestionC ontrol)
End Sub
....

[QuestionClass.vb]
Public Class Question
Public QuestionControl As New QuestionControl
Dim QuestionID As Integer
'...
Public Sub New(ByRef Question As Dataset2.QuestionRow)
QuestionID = Question.Question_ID
QuestionControl.QuestionNr.Text = Question.Question_Nr
QuestionControl.QuestionNr.CssClass = "QuestionNr"
QuestionControl.QuestionText.Text = Question.QuestionText
QuestionControl.QuestionText.CssClass = "QuestionText"
QuestionControl.QuestionHinweis.Text = Question.Hinweis
QuestionControl.QuestionHinweis.CssClass = "QuestionHinweis"
'...
End Sub
'...
End Class

[QuestionControl.ascx.vb]
Public Class QuestionControl
Inherits System.Web.UI.UserControl

#Region
Public Awnser As System.Web.UI.WebControls.PlaceHolder
Public QuestionNr As System.Web.UI.WebControls.Label
Public QuestionText As System.Web.UI.WebControls.Label
Public QuestionHinweis As System.Web.UI.WebControls.Label

'Everytime i save that file the Public of the above changes to
"Protected WithEvents"

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
InitializeComponent()
End Sub
Public Sub New()
Awnser = New System.Web.UI.WebControls.PlaceHolder
QuestionNr = New System.Web.UI.WebControls.Label
QuestionText = New System.Web.UI.WebControls.Label
QuestionHinweis = New System.Web.UI.WebControls.Label
End Sub
#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub

End Class

[QuestionControl.ascx]
<%@ Control Language="vb" AutoEventWireup="false"
Codebehind="FrageControl.ascx.vb" Inherits="umfrage.FrageControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<DIV style="WIDTH: 100%; POSITION: relative; HEIGHT: 46px"
ms_positioning="GridLayout"><asp:label id="FrageNr" style="Z-INDEX:
101; LEFT: 16px; POSITION: absolute; TOP: 16px"
BackColor="Transparent"
CssClass="QuestionNr" runat="server">FrageNr</asp:label><asp:label
id="FrageText" style="Z-INDEX: 102; LEFT: 104px; POSITION: absolute;
TOP: 16px"
CssClass="QuestionText" Width="80%" runat="server"
BorderColor="White">FrageText</asp:label><asp:label id="FrageHinweis"
style="Z-INDEX: 103; LEFT: 488px; POSITION: absolute; TOP: 16px"
CssClass="QuestionHinweis" Width="20%"
runat="server">FrageHinweis</asp:label></DIV>
<asp:placeholder id="Awnser" runat="server"></asp:placeholder>

Ok, I hope somebody can help me. Please.
Thanks in advance!

Sebastian Hiller
Nov 18 '05 #1
0 1411

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ZhangZQ | last post by:
Supposing I have a class "UserControl1 : System.Windows.Forms.UserControl" in an Assembly "UI.dll", now I create an Application project and want to use the "UserControl1" in another AppDomain, ...
1
by: jralford | last post by:
Hi, Another question from a C# newbie: I have a usercontrol class that includes a customized control. Now, if I create an instance of the class, and click on it, a click event is raised for the...
3
by: Raj Chudasama | last post by:
i have a custom control derived from usercontrol (called popupwin). I have another usercontrol (called extensionbutton). In the extension button i have declared a variable as follows: private...
2
by: Sebastian Hiller | last post by:
Hello, i'm new to .Net (i'm using VB as language and i'm working in the code-behind mode) and i can't solve the following problem: I have a WebForm and want to Add a UserControl...
2
by: Tim::.. | last post by:
Can some one please tell me why I keep getting an error saying user has not been declared when I add the following to a class usercontrol. User.Identity.Name If it is the page class then there...
0
by: N. Demos | last post by:
Hello, I have a custom usercontrol, of which I have two instances of in my aspx page. Both the usercontrol and page have codebehind. In the page codebehind, I want a member variable for each...
9
by: Richard Brown | last post by:
Can anyone give me a good argument one way or another? I have an 'address' set of fields that are used in various situations (a client has an address, a destination has an address, etc). These...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
2
by: marfi95 | last post by:
I am trying to setup a usercontrol as a base class, so that I can derive my usercontrols from it. the base is pretty simple: Imports System.Xml Public Class usrBase Inherits...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.