473,386 Members | 1,741 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.

User Web Control Load Problem

Hi,

How do I see to that an encapsulated control is surely created?

I´m trying to create a WebUserControl (A), witch is supposed to be
able to contain other WebUserControls (ie B). I´m creating the control
(A) dynamically. The problem occurs in the inner control (B).

I get the error: "The object reference is not set to an instance of an
object."
And I can see that the lblMyLabel is "Nothing" when I'm trying to set
the property Text just below here. Why is it nothing? How do I see to
that the lblMyLabel is surely created?

My inner control (B) myLabelControl:
ASCX contains this: <asp:Label id="lblMyLabel" runat="server">My
FemDLabelControl</asp:Label>
Code behind:
Public Property Text() As String
Get
EnsureChildControls()
Return lblMyLabel.Text
End Get
Set(ByVal Value As String)
EnsureChildControls()
lblMyLabel.Text = Value
End Set
End Property

My control (A) ASCX contains:
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="1" width="100%"
id="tblDetails" runat="server">
Code behind:
Private m_iAntalSektioner As Integer = 0
Private m_Sektion As Object() = {New Object}
Public Sub AddSection(ByVal Sektion As Object)
m_iAntalSektioner = m_iAntalSektioner + 1
m_Sektion(m_iAntalSektioner - 1) = Sektion
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim i As Integer
Dim row As HtmlTableRow
Dim cell As HtmlTableCell

For i = 1 To m_iAntalSektioner
Try
cell = New HtmlTableCell
cell.Attributes.Item("CLASS") = "TDBackgroundDetails"
cell.Controls.Add(m_Sektion(i - 1))
row = New HtmlTableRow
row.Cells.Add(cell)
tblDetails.Rows.Add(row)
Catch ex As System.NullReferenceException
'No section was cerated. The row couldn´t be cerated.
Try the next instead.
End Try
Next

End Sub

Testpage ASCX contains (A):
<MY:Details id="tblDetailsTable" runat="server" Titel="Test" />
Testpage Page_Load:
Dim lbl1 As myLabelControl = New myLabelControl
lbl1.Text = "Titel"
tblDetailsTable.AddSection(lbl1)

Nov 19 '05 #1
0 803

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

Similar topics

6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
1
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of...
3
by: Matej Kavčič | last post by:
Hello, i have one problem. I use loadcontrol in default.aspx page. On page i have placeholder and on load i with loadcontral load dynamic some user control. Some times i must load same user...
2
by: Sam Kuehn | last post by:
There has been a lot of articles on how to load user controls at runtime in the Init() method. UserControl myControl = (UserControl)LoadControl(stringControl); I add the control in the Init()...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
0
by: jonelling | last post by:
I am having a problem where the page load event is not being fired for certain user controls that I load dynamically in placeholders. Here is what I'm doing in brief, with full test code supplied...
8
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing...
0
by: John Smith | last post by:
I still have not gotten this damn thing figured out and I'm asking for help one last time before I give up on it. I have a user control that contains a paged gridview control. The master page...
0
by: davidr | last post by:
Hi, I have a panel that I load user Control in no problem. The problem arrises when I do a post back on one of these user controls. I have button it does a click event. In this click event I...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.