Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Problem with two instances of a custom class

Reply
Thread Tools

Problem with two instances of a custom class

 
 
anr
Guest
Posts: n/a
 
      06-11-2009
Hi all,

I have a problem with my XCalendar custom class. If I put
in the page one instance it works, but if i put two or more
throw an error like this:

"Multiple controls with the same ID".

The class is contained basically by a Textbox and
CalendarExtender control. And the error is is the
hightlighted line.

VB CLASS
Code:
Imports Microsoft.VisualBasic
Imports AjaxControlToolkit

Public Class XCalendar
    Private _date As DateTime
    Private _calendar As CalendarExtender
    Private _textbox As TextBox
    Private _defaulttext As String
    Private _backcolor As Drawing.Color
    Private _forecolor As Drawing.Color
    Private _image As Image
    Private _onclientdateselectionchanged As String
    Private _random As New Random
    Private _randomnum As String = Nothing

    ''' <summary>
    ''' (By Default "(Select)")
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property DefaultText() As String
        Get
            Return _defaulttext
        End Get
        Set(ByVal value As String)
            _defaulttext = value
        End Set
    End Property

    ''' <summary>
    ''' Control BackColor (By Default White)
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property BackColor() As Drawing.Color
        Get
            Return _backcolor
        End Get
        Set(ByVal value As Drawing.Color)
            _backcolor = value
        End Set
    End Property

    ''' <summary>
    ''' (By Default Black)
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property ForeColor() As Drawing.Color
        Get
            Return _forecolor
        End Get
        Set(ByVal value As Drawing.Color)
            _forecolor = value
        End Set
    End Property

    ''' <summary>
    ''' Returns Selected Date
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property ReturnDate() As Date
        Get
            Return _date
        End Get
    End Property

    ''' <summary>
    ''' Shows the Control XCalendar
    ''' </summary>
    ''' <param name="XDate">Date (Optional)</param>
    ''' <returns>Table with the control</returns>
    ''' <remarks></remarks>
    Public Function ShowCalendar(Optional ByVal XDate As 
DateTime = Nothing) As Table
        Dim xtable As Table
        Dim xtablerow As TableRow
        Dim xtablecell As TableCell
        Dim ximage As Image
        Dim xtextbox As TextBox
        Dim xcalendar As CalendarExtender

        ximage = New Image
        xtextbox = New TextBox
        xcalendar = New CalendarExtender

        _image = ximage
        _textbox = xtextbox
        _calendar = xcalendar
        _date = XDate

        'Assign values for the first time
        AssignDefaultValues()

        
System.Threading.Thread.CurrentThread.CurrentCulture = New 
System.Globalization.CultureInfo("en-US")

        _randomnum = Date.Now.Minute.ToString & 
Date.Now.Millisecond.ToString & _random.Next(1, 
1000000).ToString()

        _image.ImageUrl = "~/Images/Controls/Calendar.png"
        _image.ImageAlign = ImageAlign.AbsMiddle
        _image.Style.Add("Cursor", "hand")
        _image.ID = "ImageCalendar" & 
_randomnum
        _textbox.ID = "TextBoxCalendar" & _randomnum
        _calendar.TargetControlID = _textbox.ID
        _calendar.PopupButtonID = _image.ID
        _calendar.Format = "dd/MMMM/yyyy"
        _textbox.BorderWidth = 0
        _textbox.ReadOnly = True
        _textbox.Style.Add("cursor", "default")
        _textbox.Style.Add("text-transform", "capitalize")
        _textbox.Attributes.Add("onselectstart", "return 
false")
        _textbox.ReadOnly = True
        _textbox.BackColor = _backcolor
        _textbox.ForeColor = _forecolor

        xtable = New Table
        xtable.BackColor = _backcolor
        xtable.BorderWidth = 0
        xtable.CellPadding = 0
        xtable.CellSpacing = 0

        xtablerow = New TableRow
        xtablerow.BorderWidth = 0

        xtablecell = New TableCell
        xtablecell.BorderWidth = 0
        xtablecell.Width = 30
        xtablecell.Controls.Add(_image)
        xtablerow.Cells.Add(xtablecell)

        xtablecell = New TableCell
        xtablecell.BorderWidth = 0
        xtablecell.Controls.Add(_textbox)
        xtablecell.Controls.Add(_calendar)

        xtablerow.Cells.Add(xtablecell)
        xtable.Rows.Add(xtablerow)

        Return xtable
    End Function

    ''' <summary>
    ''' Assing Default values
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub AssignDefaultValues()
        If _defaulttext = Nothing Then
            _defaulttext = "(Select)"
        End If

        If _backcolor = Nothing Then
            _backcolor = Drawing.Color.White
        End If

        If _forecolor = Nothing Then
            _forecolor = Drawing.Color.Black
        End If

        If _date = Nothing Then
            _textbox.Text = _defaulttext
        Else
            _textbox.Text = _date
            _calendar.SelectedDate = _date
        End If

        'Validate Date
        _onclientdateselectionchanged = "function 
CalendarCheckDate(sender,args) { "
        _onclientdateselectionchanged = 
_onclientdateselectionchanged & "if (sender._selectedDate > 
new Date())"
        _onclientdateselectionchanged = 
_onclientdateselectionchanged & "{"
        _onclientdateselectionchanged = 
_onclientdateselectionchanged & "alert('Error:\n- The date 
cannot be higher than today');"
        _onclientdateselectionchanged = 
_onclientdateselectionchanged & "sender._selectedDate = new 
Date();"
        _onclientdateselectionchanged = 
_onclientdateselectionchanged & 
"sender._textbox.set_Value(sender._selectedDate.format(send
er._format));"
        _onclientdateselectionchanged = 
_onclientdateselectionchanged & "}"
        _onclientdateselectionchanged = 
_onclientdateselectionchanged & "}"

        _calendar.OnClientDateSelectionChanged = 
_onclientdateselectionchanged
    End Sub
End Class
Page.aspx
Code:
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" 
runat="server" />
        <asp:Label ID="LabelCalendar1" runat="server" 
Text=""></asp:Label><br />
        <asp:Label ID="LabelCalendar2" runat="server" 
Text=""></asp:Label>
    </div>
    </form>
</body>
Page.vb
Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e 
As System.EventArgs) Handles Me.Load
        Dim Calendar1 As New XCalendar
        
LabelCalendar1.Controls.Add(Calendar1.ShowCalendar(Date.Now
))

        Dim calendar2 As New XCalendar
        
LabelCalendar2.Controls.Add(calendar2.ShowCalendar(Date.Par
se("2000-05-30")))
    End Sub

When I execute Page.aspx, throw the error in the line
highlight in red

What Can I do?? (Really sorry for my bad English)


thx for the help!

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      06-12-2009
anr pretended :
> Hi all,
>
> I have a problem with my XCalendar custom class. If I put
> in the page one instance it works, but if i put two or more
> throw an error like this:
>
> "Multiple controls with the same ID".
>
> The class is contained basically by a Textbox and
> CalendarExtender control. And the error is is the
> hightlighted line.
>
> VB CLASS
> [CODE]
> Imports Microsoft.VisualBasic
> Imports AjaxControlToolkit
>
> Public Class XCalendar

[snip]
>
> What Can I do?? (Really sorry for my bad English)
>
>
> thx for the help!
>


Implement the INamingContainer interface. You don't need to do anything
special other than mention that is *does* implement that interface.

Shouldn't this control at least derive from "Control"?

Hans Kesting


 
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
Use Custom Class in another Custom Class c4tech ASP .Net 0 07-01-2009 01:57 PM
dicts,instances,containers, slotted instances, et cetera. ocschwar@gmail.com Python 8 01-29-2009 09:52 AM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Problem adding multiple instances of a custom control to aspx page Owen Evans ASP .Net Web Controls 9 06-10-2004 07:57 PM
list of class instances within a list of a class instances John Wohlbier Python 2 02-22-2004 08:41 AM



Advertisments