Thanks for sam's input.
Hi Monty,
As sam has mentioned, it's important that we call the property(which use
code to access the TextBox sub control) at the proper time during the
Usercontrol's lifecycle. If we call it too earlier within the ASP.NET
control's lifecycle, the control may haven't been created, thus it will
result to "Null reference" error... I suggest you provide some further
code logic or snippet on your usercontrol so that we can have a look into
it.
Regards,
Steven Cheng
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.

Signature
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Sam,
Good questions. In it's real branch of code sAddressBlock is not going to be
null and ipos is always greater than zero. I made a tester in VB.Net to test
all other scenarios, but at worst the value is an empty string, never "null"
or "nothing". Here's the tester:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim sAddressBlock As String = "part1" & vbCrLf & "part2" 'I
also tried these scenarios as well:
'Dim sAddressBlock As String = vbCrLf & "part2"
'Dim sAddressBlock As String = "part1" & vbCrLf
'Dim sAddressBlock As String = vbCrLf
Dim ipos As Integer = InStr(sAddressBlock, vbCrLf)
Console.WriteLine(Microsoft.VisualBasic.Strings.Left$(sAddressBlock,
ipos - 1) Is Nothing)
End Sub
As for adding the conrol, the control has already been added declaratively
in design time, like so:
<tr>
<td noWrap align="right" width="110">Address:</td>
<td><input id="txtAddress1" type="text" name="txtAddress1"
runat="server"><SPAN class="RequiredFieldMarker">*</SPAN>
<asp:requiredfieldvalidator id="RequiredFieldValidator3" runat="server"
ErrorMessage="Required Field" Display="Dynamic"
ControlToValidate="txtAddress1"></asp:requiredfieldvalidator></td>
</tr>
Thanks for any light you can shed.
> Is it the textbox that's null or the string sAddressBlock? And also,
> during what part of the user control's lifecycle are you adding the
> textbox to the user control?
sam - 30 Mar 2006 19:28 GMT
I'll just get back to you real quick on this.
No, I can't see any reason why this error is happening. You are doing
all the right things. If you missed a tag on the aspx or ascx page a
parser error would be thrown. This kindof thing happens when you
declare the textbox private or assign it a value of null in the code
behind but you aren't doing that presumably. Question: Does the page
load correctly first and then this comes up *after* that? Or does it
happen just after a compile and then always happens? From your post I
suspect the former, which means the framework is writing out the code
correctly to add your textbox to the control tree (you can check this
intermediate code - its somewhere in ASP.NET temporary files - google
for more info).
Anyway, I suspect a MS runtime error. Did you try restarting your
computer? Does it happen when you are not debugging in visual studio?
It could just be an issue with the way the VS debugger hooks into the
running process. If thats true you won't have any issues in deployment
and restarting your computer could fix your debugger for you.
Interesting problem.
Monty - 30 Mar 2006 21:48 GMT
Thanks Sam, I can't see any reason either. It hasn't happened at all to me
during debugging, only on the production machine. Again, the weird thing is
that this only happens sporadically. I did ask them to restart the web
server and now, coincidentally, they're having trouble reviving the
machine... so if it doesn't come up I guess I won't have to worry about
this! ;-)
If I figure it out I'll let you know. Anyone else have any ideas?
> I'll just get back to you real quick on this.
>
[quoted text clipped - 17 lines]
>
> Interesting problem.