bug of UniqueID property

Discussion in 'ASP .Net Web Controls' started by Popman, Aug 9, 2006.

  1. Popman

    Popman Guest

    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
     
    Popman, Aug 9, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Whitney
    Replies:
    1
    Views:
    605
    Natty Gur
    Jul 21, 2003
  2. Henri
    Replies:
    2
    Views:
    12,204
    Henri
    May 18, 2004
  3. Kepler
    Replies:
    1
    Views:
    452
    Kepler
    Jul 7, 2004
  4. =?Utf-8?B?QXJuZQ==?=

    page.UniqueID

    =?Utf-8?B?QXJuZQ==?=, Dec 7, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    644
    =?Utf-8?B?QXJuZQ==?=
    Dec 7, 2004
  5. Ken Baltrinic

    UniqueID vs. ClientID Why are they Differenct?

    Ken Baltrinic, Mar 4, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    8,806
    Ken Baltrinic
    Mar 4, 2005
Loading...

Share This Page