bug of UniqueID property

P

Popman

Hi guys,

I kind of found a bug of web control of asp.net 2.0. It's a very wierd bug.

It's about UniqueID property. Usually it works fine, but in some cases, I don't know, it does not work.
After I disassemble the assembly, I found the following code is used to generate UniqueID.

See the GetUniqueIDPrefix function below, in this function, it checked whether Me._occasionalFields.UniqueIDPrefix Is Nothing.
However, in some case, UniqueIDPrefix is an empty string instead of nothing at the first time. (I don't know why it is empty string, but it just happened to me.) So even if it has an value afterwards, the controls inside it will not have a UniqueID, which means both ID and UniqueID of child controls will be the same and then the postback that child controls raise on the client side can't be caught at the server side.


Public Overridable ReadOnly Property UniqueID As String
Get
If (Me._cachedUniqueID Is Nothing) Then
Dim control1 As Control = Me.NamingContainer
If (control1 Is Nothing) Then
Return Me._id
End If
If (Me._id Is Nothing) Then
Me.GenerateAutomaticID
End If
If (Me.Page Is control1) Then
Me._cachedUniqueID = Me._id
Else
Dim text1 As String = control1.GetUniqueIDPrefix
If (text1.Length = 0) Then
Return Me._id
End If
Me._cachedUniqueID = (text1 & Me._id)
End If
End If
Return Me._cachedUniqueID
End Get
End Property

Friend Overridable Function GetUniqueIDPrefix() As String
Me.EnsureOccasionalFields
If (Me._occasionalFields.UniqueIDPrefix Is Nothing) Then
Dim text1 As String = Me.UniqueID
If Not String.IsNullOrEmpty(text1) Then
Me._occasionalFields.UniqueIDPrefix = (text1 & Me.IdSeparator)
Else
Me._occasionalFields.UniqueIDPrefix = String.Empty
End If
End If
Return Me._occasionalFields.UniqueIDPrefix
End Function

I think if the code uses String.IsNullOrEmpty and it should fix the issue.
If String.IsNullOrEmpty(Me._occasionalFields.UniqueIDPrefix) Then


popman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top