473,883 Members | 1,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can't get dynamically created checkbox to initialize as 'checked'

dx

I'm extremely frustrated with ASP.NET...again ! To me this should be as
simple as setting oCheckBox.Check ed = True.. yet for some reason it isn't.

I have a user control (ascx) that that has a checkbox and I can't get it to
default to checked. I tried radiobuttons and experienced the same result..
can't start them as checked. The really frustrating thing is that I set the
attributes of other input controls in the Init() with no problem.

I tried setting Checked=True in the Constructor, the Init, even the Load
(which really wouldn't work for my app anyway)... none of the attempts could
get the friggin Checkbox to startup as checked.

Please Help.

Thanks in advance.
Stan

Code:
'
*************** *************** *************** *************** *************** ********
' CUSTOM DATETIME CONTROL

Public Class ctlFormEditGenP ropDate
Inherits ctlFormEditGen

Private _txtHour As TextBox
Private _txtMinute As TextBox
Private _ddlAMPM As DropDownList

Private _reqValHour As RequiredFieldVa lidator
Private _reqValMinute As RequiredFieldVa lidator

Private _calendar As Calendar
Private _dateTypeCode As String ' used to create unique IDs and
customize messaging depending on type.

Private _dDate As DateTime
Private _bDateExists As Boolean ' defines whether a date exists.
Private _sTimeZone As String ' time zone code to be
used/displayed.
Private _dateName As String ' string that is displayed in the
controls title and messaging, ie. 'Start Date'

Private WithEvents _rbtnExistYes As RadioButton
Private WithEvents _rbtnExistNo As RadioButton

Private _chkExist As CheckBox

Private WithEvents _btnEdit As Button
Private WithEvents _btnLink As LinkButton

Public Event Save(ByVal s As Object, ByVal e As EventArgs)

Public Property CalendarObject( ) As Calendar
Get
Return Me._calendar
End Get
Set(ByVal Value As Calendar)
_calendar = Value
End Set
End Property

Public Property TheDate() As DateTime
Get
Return _dDate
End Get
Set(ByVal Value As DateTime)
_dDate = Value
End Set
End Property

Public Property TimeZoneString( ) As String
Get
Return _sTimeZone
End Get
Set(ByVal Value As String)
_sTimeZone = Value.ToLower
End Set
End Property

Public Property DateExists() As Boolean
Get
Return _bDateExists
End Get
Set(ByVal Value As Boolean)
_bDateExists = Value
End Set
End Property

'Protected Sub UpdateRadioBtnS tatus()
' If Me._bDateExists Then
' _rbtnExistNo.Ch ecked = False
' _rbtnExistYes.C hecked = True
' Else
' _rbtnExistYes.C hecked = False
' _rbtnExistNo.Ch ecked = True
' End If
'End Sub

Public Sub New(ByVal sDateTypeCode As String, ByVal sDateName As
String, ByVal sTimeZone As String)
MyBase.New()

_dateTypeCode = sDateTypeCode
_dateName = sDateName

_dDate = New DateTime
_dDate = Date.UtcNow

_bDateExists = True

_sTimeZone = sTimeZone.ToLow er

_rbtnExistYes = New RadioButton
_rbtnExistYes.I D = "rbtnYes" & _dateTypeCode
_rbtnExistYes.T ext = "Yes"
_rbtnExistYes.G roupName = "DTE"
_rbtnExistYes.A utoPostBack = True
'_rbtnExistYes. EnableViewState = True
_rbtnExistYes.C hecked = True

_rbtnExistNo = New RadioButton
_rbtnExistNo.ID = "rbtnNo" & _dateTypeCode
_rbtnExistNo.Te xt = "No"
_rbtnExistNo.Gr oupName = "DTE"
_rbtnExistNo.Au toPostBack = True
'_rbtnExistNo.E nableViewState = True

_chkExist = New CheckBox
_chkExist.ID = "chkExist" & _dateTypeCode
_chkExist.Text = "This Form has a " & Me._dateName & "."
_chkExist.AutoP ostBack = True
_chkExist.Check ed = True

AddHandler _rbtnExistYes.C heckedChanged, AddressOf
OnExistsAnswere dYes
AddHandler _rbtnExistNo.Ch eckedChanged, AddressOf
OnExistsAnswere dNo

AddHandler _chkExist.Check edChanged, AddressOf OnCheckBoxClick

_calendar = New Calendar
_calendar.ID = "calendar" & _dateTypeCode
_calendar.Selec tedDate = _dDate

_calendar.Title Style.BackColor = Color.DarkGray
_calendar.BackC olor = Color.Blue
_calendar.ForeC olor = Color.White
_calendar.DaySt yle.BackColor = Color.Gray
_calendar.Selec tedDayStyle.Bac kColor = Color.LightGray
_calendar.Selec tedDayStyle.Fon t.Bold = True
_calendar.Other MonthDayStyle.B ackColor = Color.White
_calendar.Other MonthDayStyle.F oreColor = Color.LightGray
_calendar.Font. Size = Font.Size.XSmal l
_calendar.Borde rColor = Color.DarkGray
_calendar.Borde rWidth = Unit.Pixel(1)
_calendar.Borde rStyle = BorderStyle.Sol id

_btnEdit = New Button
_btnEdit.ID = "btnEdit" & _dateTypeCode
_btnEdit.Text = "Save"

_btnLink = New LinkButton
_btnLink.ID = "btnLink" & _dateTypeCode
_btnLink.Text = "Edit"
_btnLink.Causes Validation = False
_btnLink.Font.S ize = Font.Size.XSmal l

_txtHour = New TextBox
_txtHour.ID = "txtHour" & _dateTypeCode
_txtHour.MaxLen gth = 2
_txtHour.Column s = 2

_txtMinute = New TextBox
_txtMinute.ID = "txtMin" & _dateTypeCode
_txtMinute.MaxL ength = 2
_txtMinute.Colu mns = 2

_ddlAMPM = New DropDownList
_ddlAMPM.ID = "ddlAMPM" & _dateTypeCode

Dim oListItem1 As New ListItem("AM", "AM")
_ddlAMPM.Items. Add(oListItem1)
Dim oListItem2 As New ListItem("PM", "PM")
_ddlAMPM.Items. Add(oListItem2)

_reqValHour = New RequiredFieldVa lidator
_reqValHour.ID = "reqValHour " & _dateTypeCode
_reqValHour.Con trolToValidate = _txtHour.ID
_reqValHour.Err orMessage = "Enter an hour value. "
_reqValHour.Dis play = ValidatorDispla y.Dynamic

_reqValMinute = New RequiredFieldVa lidator
_reqValMinute.I D = "reqValMinu te" & _dateTypeCode
_reqValMinute.C ontrolToValidat e = _txtMinute.ID
_reqValMinute.E rrorMessage = "Enter a minute value. "
_reqValMinute.D isplay = ValidatorDispla y.Dynamic

End Sub

Private Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Init
Dim sInteger As String

_txtHour.Text = _dDate.Hour.ToS tring

sInteger = _dDate.Minute.T oString
If Len(sInteger) < 2 Then
sInteger = "0" & sInteger
End If
_txtMinute.Text = sInteger

Dim sAMPM As String
sAMPM = Right(_dDate.To ShortTimeString , 2)

_ddlAMPM.Select edValue = sAMPM

' ????!!!!!!! WTF! WILL NOT INITIALIZE TO CHECKED!
_chkExist.Check ed = True

End Sub

Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Me.Controls.Cle ar()
CreatePage()
End Sub

Protected Overrides Sub CreatePage()
MyBase.CreatePa ge()
Me.Controls.Add (_calendar)
'Me.Controls.Ad d(_reqValTitle)
Me.Controls.Add (_btnEdit)
Me.Controls.Add (_btnLink)

Me.Controls.Add (_txtHour)
Me.Controls.Add (_txtMinute)
Me.Controls.Add (_ddlAMPM)

Me.Controls.Add (_reqValHour)
Me.Controls.Add (_reqValMinute)

Me.Controls.Add (_rbtnExistYes)
Me.Controls.Add (_rbtnExistNo)

Me.Controls.Add (_chkExist)
End Sub

Protected Overridable Sub OnExistsAnswere dYes(ByVal o As Object,
ByVal e As EventArgs)
Me._calendar.En abled = True
Me._txtHour.Ena bled = True
Me._txtMinute.E nabled = True
Me._ddlAMPM.Ena bled = True
End Sub

Protected Overridable Sub OnExistsAnswere dNo(ByVal o As Object,
ByVal e As EventArgs)
Me._calendar.En abled = False
Me._txtHour.Ena bled = False
Me._txtMinute.E nabled = False
Me._ddlAMPM.Ena bled = False
End Sub

Protected Overridable Sub OnCheckBoxClick (ByVal o As Object, ByVal e
As EventArgs)
If TypeOf o Is CheckBox Then
Dim oControl As CheckBox
oControl = CType(o, CheckBox)
If oControl.Checke d Then
Me._calendar.En abled = True
Me._txtHour.Ena bled = True
Me._txtMinute.E nabled = True
Me._ddlAMPM.Ena bled = True
Else
Me._calendar.En abled = False
Me._txtHour.Ena bled = False
Me._txtMinute.E nabled = False
Me._ddlAMPM.Ena bled = False
End If
End If

End Sub

Protected Overrides Sub RenderContents( ByVal writer As
System.Web.UI.H tmlTextWriter)
writer.RenderBe ginTag(HtmlText WriterTag.P)
writer.RenderEn dTag()

' Print the Form Title text
_lblMessage.Ren derControl(writ er)

' Render the appropriate edit/save/cancel buttons
If Me.EditMode Then
' EDITMODE
writer.Write("< b>" & _dateName & " :</b> ")

_reqValHour.Ren derControl(writ er)
_reqValMinute.R enderControl(wr iter)

writer.RenderBe ginTag(HtmlText WriterTag.P)
writer.RenderEn dTag() 'p

writer.AddAttri bute(HtmlTextWr iterAttribute.C lass,
"FORM_QLABE L")
writer.RenderBe ginTag(HtmlText WriterTag.Table )

' Row that shows YES/NO
writer.RenderBe ginTag(HtmlText WriterTag.Tr)

writer.AddAttri bute(HtmlTextWr iterAttribute.C olspan, "3")
writer.AddAttri bute(HtmlTextWr iterAttribute.H eight, "50px")
writer.AddAttri bute(HtmlTextWr iterAttribute.V align, "top")
writer.RenderBe ginTag(HtmlText WriterTag.Td)

_chkExist.Rende rControl(writer )

'writer.Write(" <br>")

'writer.Write(" Does this Form have a " & Me._dateName & "?
&nbsp; ")
'_rbtnExistYes. RenderControl(w riter)
'writer.Write(" &nbsp; ")
'_rbtnExistNo.R enderControl(wr iter)

writer.RenderEn dTag() 'td

writer.RenderEn dTag() 'tr

' Title Row
writer.RenderBe ginTag(HtmlText WriterTag.Tr)
writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.Write("S elect a start Date:")
writer.RenderEn dTag() 'td

' blank cell
writer.AddAttri bute(HtmlTextWr iterAttribute.W idth, "20px")
writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.Write(" ")
writer.RenderEn dTag() 'td

writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.Write("E nter a start Time:")
writer.RenderEn dTag() 'td

' blank cell
writer.AddAttri bute(HtmlTextWr iterAttribute.W idth, "20px")
writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.Write(" ")
writer.RenderEn dTag() 'td

writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.RenderEn dTag() 'td
writer.RenderEn dTag() 'tr

writer.RenderBe ginTag(HtmlText WriterTag.Tr)
writer.RenderBe ginTag(HtmlText WriterTag.Td)

_calendar.Rende rControl(writer )

writer.RenderEn dTag() 'td

' blank cell
writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.RenderEn dTag() 'td

writer.AddAttri bute(HtmlTextWr iterAttribute.V align, "top")
writer.RenderBe ginTag(HtmlText WriterTag.Td)

_txtHour.Render Control(writer)
writer.Write(": ")
_txtMinute.Rend erControl(write r)
writer.Write(" ")
_ddlAMPM.Render Control(writer)
' timezone
writer.Write(" " & _sTimeZone)

writer.RenderEn dTag() 'td

' blank cell
writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.RenderEn dTag() 'td

writer.AddAttri bute(HtmlTextWr iterAttribute.V align, "top")
writer.RenderBe ginTag(HtmlText WriterTag.Td)

writer.Write(" ")
_btnEdit.Render Control(writer)
writer.Write(" ")
_btnLink.Text = "cancel"
_btnLink.Render Control(writer)

writer.RenderEn dTag() 'td
writer.RenderEn dTag() 'tr
writer.RenderEn dTag() 'table

Else
' DISPLAY
writer.Write("< b>" & _dateName & " :</b> ")
' Render the Title
' If no date exists then display text.
If DateExists Then
' render the time
writer.Write(Me ._dDate.ToLongD ateString)
writer.Write(" ")
writer.Write(Me ._dDate.ToShort TimeString)
' timezone
writer.Write(" " & _sTimeZone)
Else
writer.Write("D ate undefined.")
'If _dateTypeCode.E quals("START") Then
' 'customize text for date type.
'End If
End If

writer.Write(" ")
_btnLink.Text = "edit"
_btnLink.Render Control(writer)
End If
End Sub

Private Sub _btnLink_Click( ByVal sender As Object, ByVal e As
System.EventArg s) Handles _btnLink.Click
If Me.ControlState X.Equals("EDITM ODE") Then
ControlStateX = "DISPLAY"
Else
ControlStateX = "EDITMODE"
Me._calendar.Se lectedDate = Me._dDate
End If
End Sub

Private Sub _btnEdit_Click( ByVal sender As Object, ByVal e As
System.EventArg s) Handles _btnEdit.Click
OnSave(sender, e)
End Sub

Public Sub OnSave(ByVal o As Object, ByVal e As EventArgs)
'If Me._reqValTitle .IsValid Then
' RaiseEvent Save(Me, e)
'End If
End Sub

End Class

' ********** PARENT *************** *************** *************** *

Public MustInherit Class ctlFormEditGen
Inherits Panel

Protected _lblMessage As Label

Public Property ControlStateX() As String
Get
Return ViewState("Cont rolStateX")
End Get
Set(ByVal Value As String)
ViewState("Cont rolStateX") = Value
End Set
End Property

Protected ReadOnly Property EditMode() As Boolean
Get
If Me.ControlState X.Equals("EDITM ODE") Then
Return True
Else
Return False
End If
End Get
End Property

Public Property LabelMessage() As Label
Get
Return Me._lblMessage
End Get
Set(ByVal Value As Label)
_lblMessage = Value
End Set
End Property

Public Sub New()
_lblMessage = New Label
_lblMessage.Ena bleViewState = False
_lblMessage.Fon t.Bold = True
End Sub

Protected Overridable Sub CreatePage()
If IsNothing(Me.Co ntrolStateX) Then
ControlStateX = "DISPLAY"
End If
Me.Controls.Add (_lblMessage)
End Sub

Private Sub Page_PreRender( ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.PreRende r
If Me.EditMode Then
' EDITMODE
Me.BackColor = Color.LightYell ow
Else
' DISPLAY
Me.BackColor = Color.White
End If
End Sub

End Class


Nov 19 '05 #1
1 4518
Hello,

I've copy paste your code, build the control and found that.

The constructor need some parameters, this is not very normal use of a
control.
You should change the contructor: (line 75)

Public Sub New(ByVal sDateTypeCode As String, ByVal sDateName As String,
ByVal sTimeZone As String)
to a empty constructor and use 3 properties to set the values.
Keep in mind that control with postback and all need to be instanciated
without parameters.

Also, did you check if at line 187 if the SelectedValue really exist? Maybe
that code should be a try catch.

Try
_ddlAMPM.Select edValue = sAMPM
Catch ex As System.Argument OutOfRangeExcep tion
' TODO
End Try

Now the real problem, the checkbox. Well I agree with you it is not checked
with your code. I did myself a bunch of control and figure out that init
stuff should be done in CreateChildCont rols method. Try adding this....

Protected Overrides Sub CreateChildCont rols()
_chkExist.Check ed = True
End Sub

--------------------------
Jean-Claude Morin, MCP
Software Developer
2k1Soft/kCentric, Canada
"dx" <de*********@ya hoo.com> wrote in message
news:3T******** *********@fe06. lga...

I'm extremely frustrated with ASP.NET...again ! To me this should be as
simple as setting oCheckBox.Check ed = True.. yet for some reason it isn't.

I have a user control (ascx) that that has a checkbox and I can't get it to default to checked. I tried radiobuttons and experienced the same result..
can't start them as checked. The really frustrating thing is that I set the attributes of other input controls in the Init() with no problem.

I tried setting Checked=True in the Constructor, the Init, even the Load
(which really wouldn't work for my app anyway)... none of the attempts could get the friggin Checkbox to startup as checked.

Please Help.

Thanks in advance.
Stan

Code:
'
*************** *************** *************** *************** *************** *
******* ' CUSTOM DATETIME CONTROL

Public Class ctlFormEditGenP ropDate
Inherits ctlFormEditGen

Private _txtHour As TextBox
Private _txtMinute As TextBox
Private _ddlAMPM As DropDownList

Private _reqValHour As RequiredFieldVa lidator
Private _reqValMinute As RequiredFieldVa lidator

Private _calendar As Calendar
Private _dateTypeCode As String ' used to create unique IDs and
customize messaging depending on type.

Private _dDate As DateTime
Private _bDateExists As Boolean ' defines whether a date exists.
Private _sTimeZone As String ' time zone code to be
used/displayed.
Private _dateName As String ' string that is displayed in the
controls title and messaging, ie. 'Start Date'

Private WithEvents _rbtnExistYes As RadioButton
Private WithEvents _rbtnExistNo As RadioButton

Private _chkExist As CheckBox

Private WithEvents _btnEdit As Button
Private WithEvents _btnLink As LinkButton

Public Event Save(ByVal s As Object, ByVal e As EventArgs)

Public Property CalendarObject( ) As Calendar
Get
Return Me._calendar
End Get
Set(ByVal Value As Calendar)
_calendar = Value
End Set
End Property

Public Property TheDate() As DateTime
Get
Return _dDate
End Get
Set(ByVal Value As DateTime)
_dDate = Value
End Set
End Property

Public Property TimeZoneString( ) As String
Get
Return _sTimeZone
End Get
Set(ByVal Value As String)
_sTimeZone = Value.ToLower
End Set
End Property

Public Property DateExists() As Boolean
Get
Return _bDateExists
End Get
Set(ByVal Value As Boolean)
_bDateExists = Value
End Set
End Property

'Protected Sub UpdateRadioBtnS tatus()
' If Me._bDateExists Then
' _rbtnExistNo.Ch ecked = False
' _rbtnExistYes.C hecked = True
' Else
' _rbtnExistYes.C hecked = False
' _rbtnExistNo.Ch ecked = True
' End If
'End Sub

Public Sub New(ByVal sDateTypeCode As String, ByVal sDateName As
String, ByVal sTimeZone As String)
MyBase.New()

_dateTypeCode = sDateTypeCode
_dateName = sDateName

_dDate = New DateTime
_dDate = Date.UtcNow

_bDateExists = True

_sTimeZone = sTimeZone.ToLow er

_rbtnExistYes = New RadioButton
_rbtnExistYes.I D = "rbtnYes" & _dateTypeCode
_rbtnExistYes.T ext = "Yes"
_rbtnExistYes.G roupName = "DTE"
_rbtnExistYes.A utoPostBack = True
'_rbtnExistYes. EnableViewState = True
_rbtnExistYes.C hecked = True

_rbtnExistNo = New RadioButton
_rbtnExistNo.ID = "rbtnNo" & _dateTypeCode
_rbtnExistNo.Te xt = "No"
_rbtnExistNo.Gr oupName = "DTE"
_rbtnExistNo.Au toPostBack = True
'_rbtnExistNo.E nableViewState = True

_chkExist = New CheckBox
_chkExist.ID = "chkExist" & _dateTypeCode
_chkExist.Text = "This Form has a " & Me._dateName & "."
_chkExist.AutoP ostBack = True
_chkExist.Check ed = True

AddHandler _rbtnExistYes.C heckedChanged, AddressOf
OnExistsAnswere dYes
AddHandler _rbtnExistNo.Ch eckedChanged, AddressOf
OnExistsAnswere dNo

AddHandler _chkExist.Check edChanged, AddressOf OnCheckBoxClick

_calendar = New Calendar
_calendar.ID = "calendar" & _dateTypeCode
_calendar.Selec tedDate = _dDate

_calendar.Title Style.BackColor = Color.DarkGray
_calendar.BackC olor = Color.Blue
_calendar.ForeC olor = Color.White
_calendar.DaySt yle.BackColor = Color.Gray
_calendar.Selec tedDayStyle.Bac kColor = Color.LightGray
_calendar.Selec tedDayStyle.Fon t.Bold = True
_calendar.Other MonthDayStyle.B ackColor = Color.White
_calendar.Other MonthDayStyle.F oreColor = Color.LightGray
_calendar.Font. Size = Font.Size.XSmal l
_calendar.Borde rColor = Color.DarkGray
_calendar.Borde rWidth = Unit.Pixel(1)
_calendar.Borde rStyle = BorderStyle.Sol id

_btnEdit = New Button
_btnEdit.ID = "btnEdit" & _dateTypeCode
_btnEdit.Text = "Save"

_btnLink = New LinkButton
_btnLink.ID = "btnLink" & _dateTypeCode
_btnLink.Text = "Edit"
_btnLink.Causes Validation = False
_btnLink.Font.S ize = Font.Size.XSmal l

_txtHour = New TextBox
_txtHour.ID = "txtHour" & _dateTypeCode
_txtHour.MaxLen gth = 2
_txtHour.Column s = 2

_txtMinute = New TextBox
_txtMinute.ID = "txtMin" & _dateTypeCode
_txtMinute.MaxL ength = 2
_txtMinute.Colu mns = 2

_ddlAMPM = New DropDownList
_ddlAMPM.ID = "ddlAMPM" & _dateTypeCode

Dim oListItem1 As New ListItem("AM", "AM")
_ddlAMPM.Items. Add(oListItem1)
Dim oListItem2 As New ListItem("PM", "PM")
_ddlAMPM.Items. Add(oListItem2)

_reqValHour = New RequiredFieldVa lidator
_reqValHour.ID = "reqValHour " & _dateTypeCode
_reqValHour.Con trolToValidate = _txtHour.ID
_reqValHour.Err orMessage = "Enter an hour value. "
_reqValHour.Dis play = ValidatorDispla y.Dynamic

_reqValMinute = New RequiredFieldVa lidator
_reqValMinute.I D = "reqValMinu te" & _dateTypeCode
_reqValMinute.C ontrolToValidat e = _txtMinute.ID
_reqValMinute.E rrorMessage = "Enter a minute value. "
_reqValMinute.D isplay = ValidatorDispla y.Dynamic

End Sub

Private Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Init
Dim sInteger As String

_txtHour.Text = _dDate.Hour.ToS tring

sInteger = _dDate.Minute.T oString
If Len(sInteger) < 2 Then
sInteger = "0" & sInteger
End If
_txtMinute.Text = sInteger

Dim sAMPM As String
sAMPM = Right(_dDate.To ShortTimeString , 2)

_ddlAMPM.Select edValue = sAMPM

' ????!!!!!!! WTF! WILL NOT INITIALIZE TO CHECKED!
_chkExist.Check ed = True

End Sub

Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Me.Controls.Cle ar()
CreatePage()
End Sub

Protected Overrides Sub CreatePage()
MyBase.CreatePa ge()
Me.Controls.Add (_calendar)
'Me.Controls.Ad d(_reqValTitle)
Me.Controls.Add (_btnEdit)
Me.Controls.Add (_btnLink)

Me.Controls.Add (_txtHour)
Me.Controls.Add (_txtMinute)
Me.Controls.Add (_ddlAMPM)

Me.Controls.Add (_reqValHour)
Me.Controls.Add (_reqValMinute)

Me.Controls.Add (_rbtnExistYes)
Me.Controls.Add (_rbtnExistNo)

Me.Controls.Add (_chkExist)
End Sub

Protected Overridable Sub OnExistsAnswere dYes(ByVal o As Object,
ByVal e As EventArgs)
Me._calendar.En abled = True
Me._txtHour.Ena bled = True
Me._txtMinute.E nabled = True
Me._ddlAMPM.Ena bled = True
End Sub

Protected Overridable Sub OnExistsAnswere dNo(ByVal o As Object,
ByVal e As EventArgs)
Me._calendar.En abled = False
Me._txtHour.Ena bled = False
Me._txtMinute.E nabled = False
Me._ddlAMPM.Ena bled = False
End Sub

Protected Overridable Sub OnCheckBoxClick (ByVal o As Object, ByVal e As EventArgs)
If TypeOf o Is CheckBox Then
Dim oControl As CheckBox
oControl = CType(o, CheckBox)
If oControl.Checke d Then
Me._calendar.En abled = True
Me._txtHour.Ena bled = True
Me._txtMinute.E nabled = True
Me._ddlAMPM.Ena bled = True
Else
Me._calendar.En abled = False
Me._txtHour.Ena bled = False
Me._txtMinute.E nabled = False
Me._ddlAMPM.Ena bled = False
End If
End If

End Sub

Protected Overrides Sub RenderContents( ByVal writer As
System.Web.UI.H tmlTextWriter)
writer.RenderBe ginTag(HtmlText WriterTag.P)
writer.RenderEn dTag()

' Print the Form Title text
_lblMessage.Ren derControl(writ er)

' Render the appropriate edit/save/cancel buttons
If Me.EditMode Then
' EDITMODE
writer.Write("< b>" & _dateName & " :</b> ")

_reqValHour.Ren derControl(writ er)
_reqValMinute.R enderControl(wr iter)

writer.RenderBe ginTag(HtmlText WriterTag.P)
writer.RenderEn dTag() 'p

writer.AddAttri bute(HtmlTextWr iterAttribute.C lass,
"FORM_QLABE L")
writer.RenderBe ginTag(HtmlText WriterTag.Table )

' Row that shows YES/NO
writer.RenderBe ginTag(HtmlText WriterTag.Tr)

writer.AddAttri bute(HtmlTextWr iterAttribute.C olspan, "3")
writer.AddAttri bute(HtmlTextWr iterAttribute.H eight, "50px") writer.AddAttri bute(HtmlTextWr iterAttribute.V align, "top")
writer.RenderBe ginTag(HtmlText WriterTag.Td)

_chkExist.Rende rControl(writer )

'writer.Write(" <br>")

'writer.Write(" Does this Form have a " & Me._dateName & "?
&nbsp; ")
'_rbtnExistYes. RenderControl(w riter)
'writer.Write(" &nbsp; ")
'_rbtnExistNo.R enderControl(wr iter)

writer.RenderEn dTag() 'td

writer.RenderEn dTag() 'tr

' Title Row
writer.RenderBe ginTag(HtmlText WriterTag.Tr)
writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.Write("S elect a start Date:")
writer.RenderEn dTag() 'td

' blank cell
writer.AddAttri bute(HtmlTextWr iterAttribute.W idth, "20px")
writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.Write(" ")
writer.RenderEn dTag() 'td

writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.Write("E nter a start Time:")
writer.RenderEn dTag() 'td

' blank cell
writer.AddAttri bute(HtmlTextWr iterAttribute.W idth, "20px")
writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.Write(" ")
writer.RenderEn dTag() 'td

writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.RenderEn dTag() 'td
writer.RenderEn dTag() 'tr

writer.RenderBe ginTag(HtmlText WriterTag.Tr)
writer.RenderBe ginTag(HtmlText WriterTag.Td)

_calendar.Rende rControl(writer )

writer.RenderEn dTag() 'td

' blank cell
writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.RenderEn dTag() 'td

writer.AddAttri bute(HtmlTextWr iterAttribute.V align, "top")
writer.RenderBe ginTag(HtmlText WriterTag.Td)

_txtHour.Render Control(writer)
writer.Write(": ")
_txtMinute.Rend erControl(write r)
writer.Write(" ")
_ddlAMPM.Render Control(writer)
' timezone
writer.Write(" " & _sTimeZone)

writer.RenderEn dTag() 'td

' blank cell
writer.RenderBe ginTag(HtmlText WriterTag.Td)
writer.RenderEn dTag() 'td

writer.AddAttri bute(HtmlTextWr iterAttribute.V align, "top")
writer.RenderBe ginTag(HtmlText WriterTag.Td)

writer.Write(" ")
_btnEdit.Render Control(writer)
writer.Write(" ")
_btnLink.Text = "cancel"
_btnLink.Render Control(writer)

writer.RenderEn dTag() 'td
writer.RenderEn dTag() 'tr
writer.RenderEn dTag() 'table

Else
' DISPLAY
writer.Write("< b>" & _dateName & " :</b> ")
' Render the Title
' If no date exists then display text.
If DateExists Then
' render the time
writer.Write(Me ._dDate.ToLongD ateString)
writer.Write(" ")
writer.Write(Me ._dDate.ToShort TimeString)
' timezone
writer.Write(" " & _sTimeZone)
Else
writer.Write("D ate undefined.")
'If _dateTypeCode.E quals("START") Then
' 'customize text for date type.
'End If
End If

writer.Write(" ")
_btnLink.Text = "edit"
_btnLink.Render Control(writer)
End If
End Sub

Private Sub _btnLink_Click( ByVal sender As Object, ByVal e As
System.EventArg s) Handles _btnLink.Click
If Me.ControlState X.Equals("EDITM ODE") Then
ControlStateX = "DISPLAY"
Else
ControlStateX = "EDITMODE"
Me._calendar.Se lectedDate = Me._dDate
End If
End Sub

Private Sub _btnEdit_Click( ByVal sender As Object, ByVal e As
System.EventArg s) Handles _btnEdit.Click
OnSave(sender, e)
End Sub

Public Sub OnSave(ByVal o As Object, ByVal e As EventArgs)
'If Me._reqValTitle .IsValid Then
' RaiseEvent Save(Me, e)
'End If
End Sub

End Class

' ********** PARENT *************** *************** *************** *

Public MustInherit Class ctlFormEditGen
Inherits Panel

Protected _lblMessage As Label

Public Property ControlStateX() As String
Get
Return ViewState("Cont rolStateX")
End Get
Set(ByVal Value As String)
ViewState("Cont rolStateX") = Value
End Set
End Property

Protected ReadOnly Property EditMode() As Boolean
Get
If Me.ControlState X.Equals("EDITM ODE") Then
Return True
Else
Return False
End If
End Get
End Property

Public Property LabelMessage() As Label
Get
Return Me._lblMessage
End Get
Set(ByVal Value As Label)
_lblMessage = Value
End Set
End Property

Public Sub New()
_lblMessage = New Label
_lblMessage.Ena bleViewState = False
_lblMessage.Fon t.Bold = True
End Sub

Protected Overridable Sub CreatePage()
If IsNothing(Me.Co ntrolStateX) Then
ControlStateX = "DISPLAY"
End If
Me.Controls.Add (_lblMessage)
End Sub

Private Sub Page_PreRender( ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.PreRende r
If Me.EditMode Then
' EDITMODE
Me.BackColor = Color.LightYell ow
Else
' DISPLAY
Me.BackColor = Color.White
End If
End Sub

End Class

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4777
by: david | last post by:
I have an array of CheckBoxes which dynamically display in a web form. How to detect and determine which CheckBox' check status changed? For example, Array(i, j) from checked to Unchecked and Array(k,j) from unchecked to checked. Thank you. David
2
2717
by: Javier | last post by:
Hi Everyone, I have a dynamic checkbox in a datagrid that uses the ITemplate interface and has the checkchanged event wired up. When the checkbox is checked, the event event handler that handles the event gets called, however when it is unchecked, it does not fire. Is this by design, or is something else that is going on? Thanks!!. This message was originally posted by marian@discussions.microsoft.com, but
4
1954
by: sydney.luu | last post by:
Hello All, I am programmatically building a table on my web page with one row and two columns. The first column contains a web server checkbox dynamically created and the second column simply contains text of whatever I put in. This is running fine. If I check the checkbox, how would I check if this checkbox is checked or not during postback? The dynamically created checkbox seems to have disappeared during postback.
5
8410
by: Mike Fellows | last post by:
I have created some checkboxes within a panel using the code below Dim NewCheckbox As New CheckBox Me.Panel2.Controls.Add(NewCheckbox) NewCheckbox.Location = New Point(XLocation, YLocation) NewCheckbox.AutoSize = True NewCheckbox.Text = DS1.Tables(0).Rows(counter1)(0) NewCheckbox.Name = "Checkbox" & counter1 + 1
5
2033
by: SalamElias | last post by:
I am creating several chkBoxes dynamically and assigning an event handler in the Page_load as foillows ***************************** Dim chkCatOption As CheckBox = New CheckBox chkCatOption.Text = rowDS.Item("Option_Item_Desc") chkCatOption.ID = rowDS.Item("ID").ToString chkCatOption.Checked = rowDS.Item("HasOption") chkCatOption.AutoPostBack = True AddHandler chkCatOption.CheckedChanged, AddressOf AddOrUpdate
1
1633
by: theJonster | last post by:
Hi, I have created a page with a list of items and next to these items are comment boxes and check boxes which were dynamically created like this: check = new CheckBox(); check.ID = "Chk" + checkcount; if (dr.ToString() == "True") {
7
4880
by: moksha | last post by:
Hi, I am new to javascript and i am facing a problem in coding. plz help me out. I am using javascript for dynamically creating a table row which contains text boxes and radio buttons and check box. I am adding two radio buttons once for a row.Now my problem is the radio buttons in all the rows that added dynamically are behaving as same group i.e when i am selecting a radio button in second row,radio button in first row...
0
12753
acoder
by: acoder | last post by:
Problem Dynamically appended checkbox element does not appear checked despite setting the checked property state to true or "checked". Browser Internet Explorer Example The Javascript code: var cb = document.createElement("input"); cb.type = "checkbox";
3
1812
by: yogarajan | last post by:
Hi All this is my page load event protected void Page_Load(object sender, EventArgs e) { for (int i = 0; i <= 3; i++) { TableRow tr = new TableRow();
0
9943
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11151
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10419
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9577
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7974
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7134
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5804
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5996
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3237
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.