Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Composite Control and User Control

Reply
Thread Tools

Composite Control and User Control

 
 
Madison
Guest
Posts: n/a
 
      04-18-2007
Hello,

I'm working in project that I had created composite control to verify
textbox with RequiredFieldVlidator or CompareValidator or
RegularExpressionValidator. The composite control working fine on the regular
web form but when I place composite control in User Control and place User
Control in web form then I got error message: System.NullReferenceException
was unhandled by user code
Message="Object reference not set to an instance of an object." when I try
to call Composite control in User Control from web form. I do not get any
error if I call some regular asp:TextBox in user control from web form.

Thank you for any advice.
 
Reply With Quote
 
 
 
 
Shimon Sim
Guest
Posts: n/a
 
      04-18-2007
Check if you calling anything from your form in your customer control that
require Load event to fire to initialize.
In general check the order of events they may work differently if you put
your control inside of User Control.
Good luck.
"Madison" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I'm working in project that I had created composite control to verify
> textbox with RequiredFieldVlidator or CompareValidator or
> RegularExpressionValidator. The composite control working fine on the
> regular
> web form but when I place composite control in User Control and place User
> Control in web form then I got error message:
> System.NullReferenceException
> was unhandled by user code
> Message="Object reference not set to an instance of an object." when I
> try
> to call Composite control in User Control from web form. I do not get any
> error if I call some regular asp:TextBox in user control from web form.
>
> Thank you for any advice.



 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      04-19-2007
Hi Madison,

You could configure your VS2005 debugger to break whenever the
NullReferenceException occurs to see which statement is causing the error:

1) Click VS2005 menu Debug/Exceptions
2) Click on button "Find" and input "NullReferenceException", then click OK
3) After it found the exception in the list, click the checkbox at the
right side of it.

In the meanwhile, you could also show some of your code so that we can tell
more clearly what went wrong.


Regards,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      04-23-2007
Hi Madison,

Have you tried above suggestion? Please feel free to let me know if there's
anything I can help.

Regards,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Madison
Guest
Posts: n/a
 
      04-24-2007
Hi Walter,
Here is my codes. There is 3 parts
1. aspx page called user control
2. asxc user control use composite control and other asp controls
3. composite textbox control
------------------
Measure.aspx
------------------
Protected Sub ResetControls()
CustomAdmin.SectorCd_ag = Nothing ---> call user control
CustomAdmin.CalcRewardAmtInd_ag = Nothing ---> call user control
CustomAdmin.KWCalcRewardAmt_ag = Nothing ---> call user control
(problem)
CustomAdmin.KWHCalcRewardAmt_ag = Nothing ---> call user control
(problem)
CustomAdmin.ThermCalcRewardAmt_ag = Nothing ---> call user control
(problem)
End Sub

-----------------------
customAdmin.asxc (user control)
-----------------------
---------------------------------
asp:checkbox control property
---------------------------------
Property SectorCd_ag() As String
Get
If ckbSector_ag.Checked Then --->asp:checkbox
Return "A"
Else
Return ""
End If
End Get
Set(ByVal value As String)
If value = "A" Then
ckbSector_ag.Checked = True --->asp:checkbox
Else
ckbSector_ag.Checked = False --->asp:checkbox
End If
End Set
End Property
------------------------------------
asp:radioButton control property
------------------------------------
Property CalcRewardAmtInd_ag() As String
Get
Select Case rdoCalcRewardInd_ag.SelectedIndex
Case 0
Return "Y"
Case 1
Return "N"
Case Else
Return String.Empty
End Select
End Get
Set(ByVal value As String)
Select Case value
Case "Y"
rdoCalcRewardInd_ag.SelectedIndex = 0
Case "N"
rdoCalcRewardInd_ag.SelectedIndex = 1
Case Else
rdoCalcRewardInd_ag.SelectedIndex = -1
End Select
End Set
End Property
--------------------------------------
composite textbox control property
--------------------------------------
Property KWCalcRewardAmt_ag() As String
Get
Return ccKWCalcRewardAmt_ag.Text ---> composite textbox control
End Get
Set(ByVal value As String) --->called composite textbox control
(problem)
If (value Is Nothing) Then
ccKWCalcRewardAmt_ag.Text = Nothing ---> composite textbox
control
Else
ccKWCalcRewardAmt_ag.Text = value ---> composite textbox
control
End If
End Set
End Property

---------------
ccTextBox.vb (composite text box control - only part that has problem)
---------------
Public Property Text() As String
Get
Return _textbox.Text
End Get
Set(ByVal value As String) -- this is problem part
If (value Is Nothing) Then
_textbox.Text = Nothing
Else
_textbox.Text = value
End If

End Set
End Property

I got error System.NullReferenceException: Object reference not set to an
instance of an object. Source error point to Property KWCalcRewardAmt_ag in
user control and when I debug the last code is Public Property Text() in
composite control.

Any idea?


"Walter Wang [MSFT]" wrote:

> Hi Madison,
>
> Have you tried above suggestion? Please feel free to let me know if there's
> anything I can help.
>
> Regards,
> Walter Wang ((E-Mail Removed), remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      04-25-2007
Hi Madison,

Whenever you need to acccess a child control in one of your public
method/property in the composite control class, you need to call
EnsureChildControls() to make sure the child controls are created first.
You can create a private wrapper property to return a child control such as:

Public Class ccTextBox
Inherits CompositeControl

Private _textbox As TextBox

Private ReadOnly Property TheTextBox() As TextBox
Get
EnsureChildControls()
Return _textbox
End Get
End Property

Protected Overrides Sub CreateChildControls()
Controls.Clear()
_textbox = New TextBox()
Controls.Add(_textbox)
End Sub

Public Property Text() As String
Get
Return TheTextBox.Text
End Get
Set(ByVal value As String)
TheTextBox.Text = value
End Set
End Property
End Class


Hope this helps.


Regards,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Madison
Guest
Posts: n/a
 
      04-25-2007
Hi Walter,

Thank you for your help. I can refer my composite control from asp page now.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deriving a Composite Control from a User Control Itaichuk ASP .Net Building Controls 0 10-13-2007 11:32 AM
Composite vs non composite Controls Mike ASP .Net Web Controls 4 03-11-2005 05:47 AM
Losing Composite Control property that another Composite Control ... Chad ASP .Net Building Controls 0 02-01-2005 09:01 PM
Possible to create a composite control that has a child control that is a validator that validates the composite control itself? Jonathan Eric Miller ASP .Net Building Controls 2 07-22-2004 10:58 PM
Composite control with dynamic composite controls sleigh ASP .Net 1 02-12-2004 06:24 PM



Advertisments