473,386 Members | 1,621 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,386 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 1409

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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...

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.