473,739 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:Ques tionControl) 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:ques tion) 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.PlaceHolder 1.Controls.Add( QuestionObj.Que stionControlObj )". 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.v b]
....
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init

Dim QuestionObj As Question
Dim QuestionRow As Dataset2.Questi onRow
Dim QC As New QuestionControl
QuestionCollect ion = New QuestionCollect ion 'A simple
collection for the Question-Class-Objects
For Each QuestionRow In Dataset1.Questi on
QuestionObj = New Question(Questi onRow)
QuestionCollect ion.Add(Questio nObj)
Next
For Each QuestionObj In QuestionCollect ion

Me.PlaceHolder1 .Controls.Add(Q uestionObj.Ques tionControl)
End Sub
....

[QuestionClass.v b]
Public Class Question
Public QuestionControl As New QuestionControl
Dim QuestionID As Integer
'...
Public Sub New(ByRef Question As Dataset2.Questi onRow)
QuestionID = Question.Questi on_ID
QuestionControl .QuestionNr.Tex t = Question.Questi on_Nr
QuestionControl .QuestionNr.Css Class = "QuestionNr "
QuestionControl .QuestionText.T ext = Question.Questi onText
QuestionControl .QuestionText.C ssClass = "QuestionTe xt"
QuestionControl .QuestionHinwei s.Text = Question.Hinwei s
QuestionControl .QuestionHinwei s.CssClass = "QuestionHinwei s"
'...
End Sub
'...
End Class

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

#Region
Public Awnser As System.Web.UI.W ebControls.Plac eHolder
Public QuestionNr As System.Web.UI.W ebControls.Labe l
Public QuestionText As System.Web.UI.W ebControls.Labe l
Public QuestionHinweis As System.Web.UI.W ebControls.Labe l

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

Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
InitializeCompo nent()
End Sub
Public Sub New()
Awnser = New System.Web.UI.W ebControls.Plac eHolder
QuestionNr = New System.Web.UI.W ebControls.Labe l
QuestionText = New System.Web.UI.W ebControls.Labe l
QuestionHinweis = New System.Web.UI.W ebControls.Labe l
End Sub
#End Region

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

End Class

[QuestionControl .ascx]
<%@ Control Language="vb" AutoEventWireup ="false"
Codebehind="Fra geControl.ascx. vb" Inherits="umfra ge.FrageControl "
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
<DIV style="WIDTH: 100%; POSITION: relative; HEIGHT: 46px"
ms_positioning= "GridLayout"><a sp:label id="FrageNr" style="Z-INDEX:
101; LEFT: 16px; POSITION: absolute; TOP: 16px"
BackColor="Tran sparent"
CssClass="Quest ionNr" runat="server"> FrageNr</asp:label><asp: label
id="FrageText" style="Z-INDEX: 102; LEFT: 104px; POSITION: absolute;
TOP: 16px"
CssClass="Quest ionText" Width="80%" runat="server"
BorderColor="Wh ite">FrageText </asp:label><asp: label id="FrageHinwei s"
style="Z-INDEX: 103; LEFT: 488px; POSITION: absolute; TOP: 16px"
CssClass="Quest ionHinweis" Width="20%"
runat="server"> FrageHinweis</asp:label></DIV>
<asp:placeholde r id="Awnser" runat="server"> </asp:placeholder >

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

Sebastian Hiller
Nov 18 '05 #1
2 1314
Se************* *@gmx.de (Sebastian Hiller) wrote in message news:<d8******* *************** ****@posting.go ogle.com>...
[WebForm1.aspx.v b]
...
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init

Dim QuestionObj As Question
Dim QuestionRow As Dataset2.Questi onRow
Dim QC As New QuestionControl
QuestionCollect ion = New QuestionCollect ion 'A simple
collection for the Question-Class-Objects
For Each QuestionRow In Dataset1.Questi on
QuestionObj = New Question(Questi onRow)
QuestionCollect ion.Add(Questio nObj)
Next
For Each QuestionObj In QuestionCollect ion

Me.PlaceHolder1 .Controls.Add(Q uestionObj.Ques tionControl)
End Sub
...

[QuestionClass.v b]
Public Class Question
Public QuestionControl As New QuestionControl
Dim QuestionID As Integer
'...
Public Sub New(ByRef Question As Dataset2.Questi onRow)
QuestionID = Question.Questi on_ID
QuestionControl .QuestionNr.Tex t = Question.Questi on_Nr
QuestionControl .QuestionNr.Css Class = "QuestionNr "
QuestionControl .QuestionText.T ext = Question.Questi onText
QuestionControl .QuestionText.C ssClass = "QuestionTe xt"
QuestionControl .QuestionHinwei s.Text = Question.Hinwei s
QuestionControl .QuestionHinwei s.CssClass = "QuestionHinwei s"
'...
End Sub
'...
End Class
...


The Following works:
I declare an Array and give an element of that as argument to the
questionclass-constructor. But i hope there is a better solution,
because that looks ugly and i don't want to give an extra argument to
the constructor of the QuestionClass.

[WebForm1.aspc.v b]
Dim QuestionObj As Question
Dim QuestionRow As Dataset2.Questi onRow
Dim i As Integer = 0
Dim c1(100) As QuestionControl 'the Array of
QuestionControl s
QuestionCollect ion = New QuestionCollect ion
For Each QuestionRow In Dataset1.Questi on
c1(i) = LoadControl("Qu estionControl.a scx")
QuestionObj = New Question(Questi onRow, c1(i))
'QuestionContro l as arg
QuestionCollect ion.Add(Questio nObj)
i = i + 1
Next
For Each QuestionObj In QuestionCollect ion
Me.PlaceHolder1 .Controls.Add(Q uestionObj.Ques tionControl)
Next

[QuestionClass.v b]
Public Class Question
Public QuestionControl As QuestionControl
Dim QuestionID As Integer
...
Public Sub New(ByRef Question As Dataset2.Questi onRow, ByVal FC As
QuestionControl )
QuestionControl = FC
QuestionID = Question.Questi on_ID
Dim AntwortRow As Dataset2.Inhalt Row
QuestionControl .QuestionNr.Tex t = Question.Questi on_Nr
QuestionControl .QuestionNr.Css Class = "QuestionNr "
QuestionControl .QuestionText.T ext = Question.Questi onText
QuestionControl .QuestionText.C ssClass = "QuestionTe xt"
QuestionControl .QuestionHint.T ext = Question.Hint
QuestionControl .QuestionHint.C ssClass = "QuestionHi nt"
...
End Sub
End Class

I think there must be a more common way to do such a simple thing. It
must be possible to use a UserControl in the same way as a standard
WebForm Control, that is what i expect from it (and maybe others too).

With best Regrads,

Sebastian Hiller
Nov 18 '05 #2
Se************* *@gmx.de (Sebastian Hiller) wrote in message news:<d8******* *************** ****@posting.go ogle.com>...
[WebForm1.aspx.v b]
...
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init

Dim QuestionObj As Question
Dim QuestionRow As Dataset2.Questi onRow
Dim QC As New QuestionControl
QuestionCollect ion = New QuestionCollect ion 'A simple
collection for the Question-Class-Objects
For Each QuestionRow In Dataset1.Questi on
QuestionObj = New Question(Questi onRow)
QuestionCollect ion.Add(Questio nObj)
Next
For Each QuestionObj In QuestionCollect ion

Me.PlaceHolder1 .Controls.Add(Q uestionObj.Ques tionControl)
End Sub
...

[QuestionClass.v b]
Public Class Question
Public QuestionControl As New QuestionControl
Dim QuestionID As Integer
'...
Public Sub New(ByRef Question As Dataset2.Questi onRow)
QuestionID = Question.Questi on_ID
QuestionControl .QuestionNr.Tex t = Question.Questi on_Nr
QuestionControl .QuestionNr.Css Class = "QuestionNr "
QuestionControl .QuestionText.T ext = Question.Questi onText
QuestionControl .QuestionText.C ssClass = "QuestionTe xt"
QuestionControl .QuestionHinwei s.Text = Question.Hinwei s
QuestionControl .QuestionHinwei s.CssClass = "QuestionHinwei s"
'...
End Sub
'...
End Class
...


The Following works:
I declare an Array and give an element of that as argument to the
questionclass-constructor. But i hope there is a better solution,
because that looks ugly and i don't want to give an extra argument to
the constructor of the QuestionClass.

[WebForm1.aspc.v b]
Dim QuestionObj As Question
Dim QuestionRow As Dataset2.Questi onRow
Dim i As Integer = 0
Dim c1(100) As QuestionControl 'the Array of
QuestionControl s
QuestionCollect ion = New QuestionCollect ion
For Each QuestionRow In Dataset1.Questi on
c1(i) = LoadControl("Qu estionControl.a scx")
QuestionObj = New Question(Questi onRow, c1(i))
'QuestionContro l as arg
QuestionCollect ion.Add(Questio nObj)
i = i + 1
Next
For Each QuestionObj In QuestionCollect ion
Me.PlaceHolder1 .Controls.Add(Q uestionObj.Ques tionControl)
Next

[QuestionClass.v b]
Public Class Question
Public QuestionControl As QuestionControl
Dim QuestionID As Integer
...
Public Sub New(ByRef Question As Dataset2.Questi onRow, ByVal FC As
QuestionControl )
QuestionControl = FC
QuestionID = Question.Questi on_ID
Dim AntwortRow As Dataset2.Inhalt Row
QuestionControl .QuestionNr.Tex t = Question.Questi on_Nr
QuestionControl .QuestionNr.Css Class = "QuestionNr "
QuestionControl .QuestionText.T ext = Question.Questi onText
QuestionControl .QuestionText.C ssClass = "QuestionTe xt"
QuestionControl .QuestionHint.T ext = Question.Hint
QuestionControl .QuestionHint.C ssClass = "QuestionHi nt"
...
End Sub
End Class

I think there must be a more common way to do such a simple thing. It
must be possible to use a UserControl in the same way as a standard
WebForm Control, that is what i expect from it (and maybe others too).

With best Regrads
Nov 18 '05 #3

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

Similar topics

3
3968
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, private void CreateUIInAnotherDomain() { UI.UserControl1 ui = (UI.Cls)domain.CreateInstanceFromAndUnwrap(@".\UI.dll", "UI.UserControl1"); this.Controls.Add(ui);
1
3032
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 customized control within the class. This is good. What I also want is to raise a click event for the class itself. For instance,
3
2695
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 PopupWindow mUserPopWin; i create a new instance of the popupwin and provide necessary vars. this.mUserPopWin = new PopupWindow(); this.mUserPopWin.UserName = this.List.Name;
0
1434
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 (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...
2
1267
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 is no problem!!! EG: Inherits System.Web.UI.Page = OK
0
1532
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 usercontrol. My problem is that I keep getting a compiler error on the usercontrol variables in my page codebehind (BC30002: Type 'CityGeoPosSelectClass' is not defined.) For whatever reason, my usercontrol class is not being declared in the page...
9
3348
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 fields are all normalized into a seperate database table from the client and destination tables. My question is, which is better to create, a User Control, or a generic class that will add controls to a form directly, applying its common event...
5
1640
by: Jim Hubbard | last post by:
I have created a simple usercontrol that adds functionality to the webbrowser control (let's call it ctrl1). I would like to add it to another usercontrol I am creating (let's call it ctrl2), but I can't INHERIT ctrl1 into ctrl2 because I can only use a single INHERITS statement in a class and doing so would eliminate the "Inherits System.Windows.Forms.UserControl" statement needed tom implement ctrl2. Any suggestions?
41
4315
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 on some initialization information obtained elsewhere. Basically, I'm going to create my own dynamic toolbar where the toolbarbuttons can change. I'm not using the VB toolbar because of limitations in changing things like backcolor (I can't get...
2
3008
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 System.Windows.Forms.UserControl Public Overridable Sub MethodA()
0
8792
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9479
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9266
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9209
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3280
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.