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 & "?
")
'_rbtnExistYes. RenderControl(w riter)
'writer.Write(" ")
'_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 1 4508
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 & "? ") '_rbtnExistYes. RenderControl(w riter) 'writer.Write(" ") '_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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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
|
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.
|
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
|
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
| |
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")
{
|
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...
|
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";
|
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();
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |