By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,786 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,786 IT Pros & Developers. It's quick & easy.

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

P: n/a
dx

I'm extremely frustrated with ASP.NET...again! To me this should be as
simple as setting oCheckBox.Checked = 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 ctlFormEditGenPropDate
Inherits ctlFormEditGen

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

Private _reqValHour As RequiredFieldValidator
Private _reqValMinute As RequiredFieldValidator

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 UpdateRadioBtnStatus()
' If Me._bDateExists Then
' _rbtnExistNo.Checked = False
' _rbtnExistYes.Checked = True
' Else
' _rbtnExistYes.Checked = False
' _rbtnExistNo.Checked = 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.ToLower

_rbtnExistYes = New RadioButton
_rbtnExistYes.ID = "rbtnYes" & _dateTypeCode
_rbtnExistYes.Text = "Yes"
_rbtnExistYes.GroupName = "DTE"
_rbtnExistYes.AutoPostBack = True
'_rbtnExistYes.EnableViewState = True
_rbtnExistYes.Checked = True

_rbtnExistNo = New RadioButton
_rbtnExistNo.ID = "rbtnNo" & _dateTypeCode
_rbtnExistNo.Text = "No"
_rbtnExistNo.GroupName = "DTE"
_rbtnExistNo.AutoPostBack = True
'_rbtnExistNo.EnableViewState = True

_chkExist = New CheckBox
_chkExist.ID = "chkExist" & _dateTypeCode
_chkExist.Text = "This Form has a " & Me._dateName & "."
_chkExist.AutoPostBack = True
_chkExist.Checked = True

AddHandler _rbtnExistYes.CheckedChanged, AddressOf
OnExistsAnsweredYes
AddHandler _rbtnExistNo.CheckedChanged, AddressOf
OnExistsAnsweredNo

AddHandler _chkExist.CheckedChanged, AddressOf OnCheckBoxClick

_calendar = New Calendar
_calendar.ID = "calendar" & _dateTypeCode
_calendar.SelectedDate = _dDate

_calendar.TitleStyle.BackColor = Color.DarkGray
_calendar.BackColor = Color.Blue
_calendar.ForeColor = Color.White
_calendar.DayStyle.BackColor = Color.Gray
_calendar.SelectedDayStyle.BackColor = Color.LightGray
_calendar.SelectedDayStyle.Font.Bold = True
_calendar.OtherMonthDayStyle.BackColor = Color.White
_calendar.OtherMonthDayStyle.ForeColor = Color.LightGray
_calendar.Font.Size = Font.Size.XSmall
_calendar.BorderColor = Color.DarkGray
_calendar.BorderWidth = Unit.Pixel(1)
_calendar.BorderStyle = BorderStyle.Solid

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

_btnLink = New LinkButton
_btnLink.ID = "btnLink" & _dateTypeCode
_btnLink.Text = "Edit"
_btnLink.CausesValidation = False
_btnLink.Font.Size = Font.Size.XSmall

_txtHour = New TextBox
_txtHour.ID = "txtHour" & _dateTypeCode
_txtHour.MaxLength = 2
_txtHour.Columns = 2

_txtMinute = New TextBox
_txtMinute.ID = "txtMin" & _dateTypeCode
_txtMinute.MaxLength = 2
_txtMinute.Columns = 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 RequiredFieldValidator
_reqValHour.ID = "reqValHour" & _dateTypeCode
_reqValHour.ControlToValidate = _txtHour.ID
_reqValHour.ErrorMessage = "Enter an hour value. "
_reqValHour.Display = ValidatorDisplay.Dynamic

_reqValMinute = New RequiredFieldValidator
_reqValMinute.ID = "reqValMinute" & _dateTypeCode
_reqValMinute.ControlToValidate = _txtMinute.ID
_reqValMinute.ErrorMessage = "Enter a minute value. "
_reqValMinute.Display = ValidatorDisplay.Dynamic

End Sub

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

_txtHour.Text = _dDate.Hour.ToString

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

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

_ddlAMPM.SelectedValue = sAMPM

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

End Sub

Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Controls.Clear()
CreatePage()
End Sub

Protected Overrides Sub CreatePage()
MyBase.CreatePage()
Me.Controls.Add(_calendar)
'Me.Controls.Add(_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 OnExistsAnsweredYes(ByVal o As Object,
ByVal e As EventArgs)
Me._calendar.Enabled = True
Me._txtHour.Enabled = True
Me._txtMinute.Enabled = True
Me._ddlAMPM.Enabled = True
End Sub

Protected Overridable Sub OnExistsAnsweredNo(ByVal o As Object,
ByVal e As EventArgs)
Me._calendar.Enabled = False
Me._txtHour.Enabled = False
Me._txtMinute.Enabled = False
Me._ddlAMPM.Enabled = 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.Checked Then
Me._calendar.Enabled = True
Me._txtHour.Enabled = True
Me._txtMinute.Enabled = True
Me._ddlAMPM.Enabled = True
Else
Me._calendar.Enabled = False
Me._txtHour.Enabled = False
Me._txtMinute.Enabled = False
Me._ddlAMPM.Enabled = False
End If
End If

End Sub

Protected Overrides Sub RenderContents(ByVal writer As
System.Web.UI.HtmlTextWriter)
writer.RenderBeginTag(HtmlTextWriterTag.P)
writer.RenderEndTag()

' Print the Form Title text
_lblMessage.RenderControl(writer)

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

_reqValHour.RenderControl(writer)
_reqValMinute.RenderControl(writer)

writer.RenderBeginTag(HtmlTextWriterTag.P)
writer.RenderEndTag() 'p

writer.AddAttribute(HtmlTextWriterAttribute.Class,
"FORM_QLABEL")
writer.RenderBeginTag(HtmlTextWriterTag.Table)

' Row that shows YES/NO
writer.RenderBeginTag(HtmlTextWriterTag.Tr)

writer.AddAttribute(HtmlTextWriterAttribute.Colspa n, "3")
writer.AddAttribute(HtmlTextWriterAttribute.Height , "50px")
writer.AddAttribute(HtmlTextWriterAttribute.Valign , "top")
writer.RenderBeginTag(HtmlTextWriterTag.Td)

_chkExist.RenderControl(writer)

'writer.Write("<br>")

'writer.Write("Does this Form have a " & Me._dateName & "?
&nbsp; ")
'_rbtnExistYes.RenderControl(writer)
'writer.Write(" &nbsp; ")
'_rbtnExistNo.RenderControl(writer)

writer.RenderEndTag() 'td

writer.RenderEndTag() 'tr

' Title Row
writer.RenderBeginTag(HtmlTextWriterTag.Tr)
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.Write("Select a start Date:")
writer.RenderEndTag() 'td

' blank cell
writer.AddAttribute(HtmlTextWriterAttribute.Width, "20px")
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.Write(" ")
writer.RenderEndTag() 'td

writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.Write("Enter a start Time:")
writer.RenderEndTag() 'td

' blank cell
writer.AddAttribute(HtmlTextWriterAttribute.Width, "20px")
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.Write(" ")
writer.RenderEndTag() 'td

writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.RenderEndTag() 'td
writer.RenderEndTag() 'tr

writer.RenderBeginTag(HtmlTextWriterTag.Tr)
writer.RenderBeginTag(HtmlTextWriterTag.Td)

_calendar.RenderControl(writer)

writer.RenderEndTag() 'td

' blank cell
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.RenderEndTag() 'td

writer.AddAttribute(HtmlTextWriterAttribute.Valign , "top")
writer.RenderBeginTag(HtmlTextWriterTag.Td)

_txtHour.RenderControl(writer)
writer.Write(":")
_txtMinute.RenderControl(writer)
writer.Write(" ")
_ddlAMPM.RenderControl(writer)
' timezone
writer.Write(" " & _sTimeZone)

writer.RenderEndTag() 'td

' blank cell
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.RenderEndTag() 'td

writer.AddAttribute(HtmlTextWriterAttribute.Valign , "top")
writer.RenderBeginTag(HtmlTextWriterTag.Td)

writer.Write(" ")
_btnEdit.RenderControl(writer)
writer.Write(" ")
_btnLink.Text = "cancel"
_btnLink.RenderControl(writer)

writer.RenderEndTag() 'td
writer.RenderEndTag() 'tr
writer.RenderEndTag() '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.ToLongDateString)
writer.Write(" ")
writer.Write(Me._dDate.ToShortTimeString)
' timezone
writer.Write(" " & _sTimeZone)
Else
writer.Write("Date undefined.")
'If _dateTypeCode.Equals("START") Then
' 'customize text for date type.
'End If
End If

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

Private Sub _btnLink_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles _btnLink.Click
If Me.ControlStateX.Equals("EDITMODE") Then
ControlStateX = "DISPLAY"
Else
ControlStateX = "EDITMODE"
Me._calendar.SelectedDate = Me._dDate
End If
End Sub

Private Sub _btnEdit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) 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("ControlStateX")
End Get
Set(ByVal Value As String)
ViewState("ControlStateX") = Value
End Set
End Property

Protected ReadOnly Property EditMode() As Boolean
Get
If Me.ControlStateX.Equals("EDITMODE") 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.EnableViewState = False
_lblMessage.Font.Bold = True
End Sub

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

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
If Me.EditMode Then
' EDITMODE
Me.BackColor = Color.LightYellow
Else
' DISPLAY
Me.BackColor = Color.White
End If
End Sub

End Class


Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.SelectedValue = sAMPM
Catch ex As System.ArgumentOutOfRangeException
' 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 CreateChildControls method. Try adding this....

Protected Overrides Sub CreateChildControls()
_chkExist.Checked = True
End Sub

--------------------------
Jean-Claude Morin, MCP
Software Developer
2k1Soft/kCentric, Canada
"dx" <de*********@yahoo.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.Checked = 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 ctlFormEditGenPropDate
Inherits ctlFormEditGen

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

Private _reqValHour As RequiredFieldValidator
Private _reqValMinute As RequiredFieldValidator

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 UpdateRadioBtnStatus()
' If Me._bDateExists Then
' _rbtnExistNo.Checked = False
' _rbtnExistYes.Checked = True
' Else
' _rbtnExistYes.Checked = False
' _rbtnExistNo.Checked = 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.ToLower

_rbtnExistYes = New RadioButton
_rbtnExistYes.ID = "rbtnYes" & _dateTypeCode
_rbtnExistYes.Text = "Yes"
_rbtnExistYes.GroupName = "DTE"
_rbtnExistYes.AutoPostBack = True
'_rbtnExistYes.EnableViewState = True
_rbtnExistYes.Checked = True

_rbtnExistNo = New RadioButton
_rbtnExistNo.ID = "rbtnNo" & _dateTypeCode
_rbtnExistNo.Text = "No"
_rbtnExistNo.GroupName = "DTE"
_rbtnExistNo.AutoPostBack = True
'_rbtnExistNo.EnableViewState = True

_chkExist = New CheckBox
_chkExist.ID = "chkExist" & _dateTypeCode
_chkExist.Text = "This Form has a " & Me._dateName & "."
_chkExist.AutoPostBack = True
_chkExist.Checked = True

AddHandler _rbtnExistYes.CheckedChanged, AddressOf
OnExistsAnsweredYes
AddHandler _rbtnExistNo.CheckedChanged, AddressOf
OnExistsAnsweredNo

AddHandler _chkExist.CheckedChanged, AddressOf OnCheckBoxClick

_calendar = New Calendar
_calendar.ID = "calendar" & _dateTypeCode
_calendar.SelectedDate = _dDate

_calendar.TitleStyle.BackColor = Color.DarkGray
_calendar.BackColor = Color.Blue
_calendar.ForeColor = Color.White
_calendar.DayStyle.BackColor = Color.Gray
_calendar.SelectedDayStyle.BackColor = Color.LightGray
_calendar.SelectedDayStyle.Font.Bold = True
_calendar.OtherMonthDayStyle.BackColor = Color.White
_calendar.OtherMonthDayStyle.ForeColor = Color.LightGray
_calendar.Font.Size = Font.Size.XSmall
_calendar.BorderColor = Color.DarkGray
_calendar.BorderWidth = Unit.Pixel(1)
_calendar.BorderStyle = BorderStyle.Solid

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

_btnLink = New LinkButton
_btnLink.ID = "btnLink" & _dateTypeCode
_btnLink.Text = "Edit"
_btnLink.CausesValidation = False
_btnLink.Font.Size = Font.Size.XSmall

_txtHour = New TextBox
_txtHour.ID = "txtHour" & _dateTypeCode
_txtHour.MaxLength = 2
_txtHour.Columns = 2

_txtMinute = New TextBox
_txtMinute.ID = "txtMin" & _dateTypeCode
_txtMinute.MaxLength = 2
_txtMinute.Columns = 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 RequiredFieldValidator
_reqValHour.ID = "reqValHour" & _dateTypeCode
_reqValHour.ControlToValidate = _txtHour.ID
_reqValHour.ErrorMessage = "Enter an hour value. "
_reqValHour.Display = ValidatorDisplay.Dynamic

_reqValMinute = New RequiredFieldValidator
_reqValMinute.ID = "reqValMinute" & _dateTypeCode
_reqValMinute.ControlToValidate = _txtMinute.ID
_reqValMinute.ErrorMessage = "Enter a minute value. "
_reqValMinute.Display = ValidatorDisplay.Dynamic

End Sub

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

_txtHour.Text = _dDate.Hour.ToString

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

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

_ddlAMPM.SelectedValue = sAMPM

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

End Sub

Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Controls.Clear()
CreatePage()
End Sub

Protected Overrides Sub CreatePage()
MyBase.CreatePage()
Me.Controls.Add(_calendar)
'Me.Controls.Add(_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 OnExistsAnsweredYes(ByVal o As Object,
ByVal e As EventArgs)
Me._calendar.Enabled = True
Me._txtHour.Enabled = True
Me._txtMinute.Enabled = True
Me._ddlAMPM.Enabled = True
End Sub

Protected Overridable Sub OnExistsAnsweredNo(ByVal o As Object,
ByVal e As EventArgs)
Me._calendar.Enabled = False
Me._txtHour.Enabled = False
Me._txtMinute.Enabled = False
Me._ddlAMPM.Enabled = 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.Checked Then
Me._calendar.Enabled = True
Me._txtHour.Enabled = True
Me._txtMinute.Enabled = True
Me._ddlAMPM.Enabled = True
Else
Me._calendar.Enabled = False
Me._txtHour.Enabled = False
Me._txtMinute.Enabled = False
Me._ddlAMPM.Enabled = False
End If
End If

End Sub

Protected Overrides Sub RenderContents(ByVal writer As
System.Web.UI.HtmlTextWriter)
writer.RenderBeginTag(HtmlTextWriterTag.P)
writer.RenderEndTag()

' Print the Form Title text
_lblMessage.RenderControl(writer)

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

_reqValHour.RenderControl(writer)
_reqValMinute.RenderControl(writer)

writer.RenderBeginTag(HtmlTextWriterTag.P)
writer.RenderEndTag() 'p

writer.AddAttribute(HtmlTextWriterAttribute.Class,
"FORM_QLABEL")
writer.RenderBeginTag(HtmlTextWriterTag.Table)

' Row that shows YES/NO
writer.RenderBeginTag(HtmlTextWriterTag.Tr)

writer.AddAttribute(HtmlTextWriterAttribute.Colspa n, "3")
writer.AddAttribute(HtmlTextWriterAttribute.Height , "50px") writer.AddAttribute(HtmlTextWriterAttribute.Valign , "top")
writer.RenderBeginTag(HtmlTextWriterTag.Td)

_chkExist.RenderControl(writer)

'writer.Write("<br>")

'writer.Write("Does this Form have a " & Me._dateName & "?
&nbsp; ")
'_rbtnExistYes.RenderControl(writer)
'writer.Write(" &nbsp; ")
'_rbtnExistNo.RenderControl(writer)

writer.RenderEndTag() 'td

writer.RenderEndTag() 'tr

' Title Row
writer.RenderBeginTag(HtmlTextWriterTag.Tr)
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.Write("Select a start Date:")
writer.RenderEndTag() 'td

' blank cell
writer.AddAttribute(HtmlTextWriterAttribute.Width, "20px")
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.Write(" ")
writer.RenderEndTag() 'td

writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.Write("Enter a start Time:")
writer.RenderEndTag() 'td

' blank cell
writer.AddAttribute(HtmlTextWriterAttribute.Width, "20px")
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.Write(" ")
writer.RenderEndTag() 'td

writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.RenderEndTag() 'td
writer.RenderEndTag() 'tr

writer.RenderBeginTag(HtmlTextWriterTag.Tr)
writer.RenderBeginTag(HtmlTextWriterTag.Td)

_calendar.RenderControl(writer)

writer.RenderEndTag() 'td

' blank cell
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.RenderEndTag() 'td

writer.AddAttribute(HtmlTextWriterAttribute.Valign , "top")
writer.RenderBeginTag(HtmlTextWriterTag.Td)

_txtHour.RenderControl(writer)
writer.Write(":")
_txtMinute.RenderControl(writer)
writer.Write(" ")
_ddlAMPM.RenderControl(writer)
' timezone
writer.Write(" " & _sTimeZone)

writer.RenderEndTag() 'td

' blank cell
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.RenderEndTag() 'td

writer.AddAttribute(HtmlTextWriterAttribute.Valign , "top")
writer.RenderBeginTag(HtmlTextWriterTag.Td)

writer.Write(" ")
_btnEdit.RenderControl(writer)
writer.Write(" ")
_btnLink.Text = "cancel"
_btnLink.RenderControl(writer)

writer.RenderEndTag() 'td
writer.RenderEndTag() 'tr
writer.RenderEndTag() '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.ToLongDateString)
writer.Write(" ")
writer.Write(Me._dDate.ToShortTimeString)
' timezone
writer.Write(" " & _sTimeZone)
Else
writer.Write("Date undefined.")
'If _dateTypeCode.Equals("START") Then
' 'customize text for date type.
'End If
End If

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

Private Sub _btnLink_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles _btnLink.Click
If Me.ControlStateX.Equals("EDITMODE") Then
ControlStateX = "DISPLAY"
Else
ControlStateX = "EDITMODE"
Me._calendar.SelectedDate = Me._dDate
End If
End Sub

Private Sub _btnEdit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) 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("ControlStateX")
End Get
Set(ByVal Value As String)
ViewState("ControlStateX") = Value
End Set
End Property

Protected ReadOnly Property EditMode() As Boolean
Get
If Me.ControlStateX.Equals("EDITMODE") 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.EnableViewState = False
_lblMessage.Font.Bold = True
End Sub

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

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
If Me.EditMode Then
' EDITMODE
Me.BackColor = Color.LightYellow
Else
' DISPLAY
Me.BackColor = Color.White
End If
End Sub

End Class

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.