473,500 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic user control and validation

Hi,

I've been working on a custom user control that needs to be modified
and the validation is causing me headaches.

The control used to generate a table of 4 rows x 7 columns to display
all the days in the week with dates and textboxes to fill in some
data.

row 1: question
row 2: days of the week
row 3: dates for the days of the week
row 4: textboxes to enter data for each day of the week

The control was using 4 procedures to generate its rows, each
procedure generates a row using loops for each days of the week. It
was using a series of RenderBeginTag, add content, RenderEndTag and
RenderControl calls

A required field validator is instantiated created on the onload event
of the user control, then added to the control array

At some point during the table generation, the validator is rendered
in a cell.

That works fine.

But now, I had to modify the layout to display 4 columns by 7 rows. I
can no longer treat the data "per row".

So i created all the rows upfront using a WebControl.Table control. I
dynamically create rows and add the cells on the fly
then at the end, call the WebControl.Table RenderControl method.

The problem I have with that is that the validator wont work. I know
it has to be added to the control array of the user control but using
my technique i can no longer tell it to render in X or Y cell of the
table. (or am i wrong ?)

I think i know what i have to do but i have no idea how to do it. I'm
pretty new to controls like that (without a .asmx) I've already
searched a lot on google without finding anything that could help me
understand.

Could someone help me ?

Here's some Before and After code to make it clearer ...

' ************ PREVIOUS CONTROL *******************
Protected Overrides Sub CreateChildControls()
'lots of line skipped to show only what matters
'---VALIDATORS---
If EditMode = True Then
custValRegularHours = New CustomValidator
custValRegularHours.EnableViewState = False
custValRegularHours.EnableClientScript = False
custValRegularHours.Display = ValidatorDisplay.Dynamic
Controls.Add(custValRegularHours)

reqLDWRegularHoursRow = New RequiredFieldValidator
reqLDWRegularHoursRow.ControlToValidate =
"txtLDWRegularHoursRow"
reqLDWRegularHoursRow.Display =
ValidatorDisplay.Dynamic
reqLDWRegularHoursRow.EnableClientScript = False
Controls.Add(reqLDWRegularHoursRow) 'add validator to
control array of user control.

'---STYLE SHEET---
If ValidatorCSSClass <String.Empty Then
custValRegularHours.CssClass = ValidatorCSSClass
reqLDWRegularHoursRow.CssClass = ValidatorCSSClass
End If
End If

End Sub

Protected Overrides Sub RenderContents(ByVal writer As
System.Web.UI.HtmlTextWriter)
'Render all the various rows of the table

RenderLWEarningsTableBeginTag(writer)
RenderLWEarningsTitleLabelRow(writer)
RenderLblLWEarningsDaysLabelRow(writer)
RenderLWEarningsDateDataRow(writer)
RenderLWEarningsRegHoursDataRow(writer)
End Sub

'*** <Table>
Protected Sub RenderLWEarningsTableBeginTag(ByVal output As
System.Web.UI.HtmlTextWriter)
'<table>
output.AddAttribute(HtmlTextWriterAttribute.Cellsp acing,
"0")
output.AddAttribute(HtmlTextWriterAttribute.Cellpa dding,
"2")
output.AddAttribute(HtmlTextWriterAttribute.Width, "400")
output.AddAttribute(HtmlTextWriterAttribute.Border , "0")
output.RenderBeginTag(HtmlTextWriterTag.Table)
End Sub

'*** TITLE
Protected Sub RenderLWEarningsTitleLabelRow(ByVal output As
System.Web.UI.HtmlTextWriter)
'- TABLE ROW FOR TITLE**************************
'<tr>
output.RenderBeginTag(HtmlTextWriterTag.Tr)
'<td>
If EditMode = False Then
output.AddAttribute(HtmlTextWriterAttribute.Colspa n,
"9")
Else
output.AddAttribute(HtmlTextWriterAttribute.Colspa n,
"8")
End If
output.RenderBeginTag(HtmlTextWriterTag.Td)
output.Write("<span class=bigred>*</span>&nbsp;")
lblTitle.RenderControl(output)
If EditMode = True Then
output.Write("&nbsp;")

'Render the validators at the appropriate area in the table

reqLDWRegularHoursRow.RenderControl(output)
custValRegularHours.RenderControl(output)

End If
'</td>
output.RenderEndTag()
'</tr>
output.RenderEndTag()
'TABLE ROW FOR TITLE**************************
End Sub

' ************ CURRENT CONTROL *******************

Protected Overrides Sub CreateChildControls()
'---VALIDATORS---
If EditMode Then
custValRegularHours = New CustomValidator
custValRegularHours.EnableViewState = False
custValRegularHours.EnableClientScript = False
custValRegularHours.Display = ValidatorDisplay.Dynamic
Controls.Add(custValRegularHours)

reqLDWRegularHoursRow = New RequiredFieldValidator
reqLDWRegularHoursRow.ControlToValidate =
"txtLDWRegularHoursRow"
reqLDWRegularHoursRow.Display = ValidatorDisplay.Dynamic
reqLDWRegularHoursRow.EnableClientScript = False
Controls.Add(reqLDWRegularHoursRow)

'---STYLE SHEET---
If ValidatorCSSClass <String.Empty Then
custValRegularHours.CssClass = ValidatorCSSClass
reqLDWRegularHoursRow.CssClass = ValidatorCSSClass
End If
End If
End Sub

Protected Overrides Sub RenderContents(ByVal writer As
System.Web.UI.HtmlTextWriter)

LWETable = New Table

RenderLWEarningsTableBeginTag() 'instantiate table, create
all rows
RenderLWEarningsTitleLabelRow() 'question
RenderLblLWEarningsDaysLabelRow() 'headers
RenderLWEarningsDateDataRow() 'Dates
RenderLWEarningsRegHoursDataRow() 'Hours

'Render the whole table in the writer
LWETable.RenderControl(writer)

End Sub

Protected Sub RenderLWEarningsTableBeginTag()
Dim i As Integer
Dim aCell As TableHeaderCell 'th
Dim aLabel As Label

LWETable.Attributes.Add("cellpadding", "0")
LWETable.Attributes.Add("cellspacing", "0")
LWETable.Attributes.Add("border", "0")
LWETable.Attributes.Add("width", "495")

'Create all the rows right up front
LWETable.Rows.Add(New TableRow) 'Title
LWETable.Rows.Add(New TableRow) 'Header
LWETable.Rows.Add(New TableRow) 'Sunday
LWETable.Rows.Add(New TableRow) 'Monday
LWETable.Rows.Add(New TableRow) 'Tuesday
LWETable.Rows.Add(New TableRow) 'Wednesday
LWETable.Rows.Add(New TableRow) 'Thursday
LWETable.Rows.Add(New TableRow) 'Friday
LWETable.Rows.Add(New TableRow) 'Saturday
LWETable.Rows.Add(New TableRow) 'Footer

If DaysOfWeek.Count = 0 Then
SetDayArray()
End If

'Write the days in the first cell of the rows
For i = 0 To DaysOfWeek.Count - 1
'<td>
aCell = New TableHeaderCell
aCell.HorizontalAlign = HorizontalAlign.Left

lblDays.ID = strDaysOfWeekDisplay.Item(i)
lblDays.Text = strDaysOfWeekDisplay.Item(i)

aLabel = QuickClone(lblDays)
' aLabel.ID &= "_" & i

aCell.Controls.Add(aLabel)

'2 is the number of rows before the rows for the days
LWETable.Rows(2 + i).Cells.Add(aCell)
Next

If EditMode = False Then
aCell = New TableHeaderCell
aCell.HorizontalAlign = HorizontalAlign.Center
aCell.Controls.Add(lblTotal)

LWETable.Rows(TableRows.Footer).Cells.Add(aCell)
End If
End Sub

'*** TITLE
Protected Sub RenderLWEarningsTitleLabelRow()
Dim curRow As TableRow = LWETable.Rows(TableRows.Title)
Dim aCell As TableCell
'- TABLE ROW FOR TITLE**************************
'<td>
aCell = New TableCell
If EditMode = False Then
aCell.ColumnSpan = 3
Else
aCell.ColumnSpan = 3
End If
Dim aSpan As HtmlGenericControl = New
HtmlGenericControl("span")
aSpan.InnerText = "*"
aSpan.Attributes.Add("class", "mandatory")
aCell.Controls.Add(aSpan)
aCell.Controls.Add(lblTitle)

If EditMode = True Then
'i know i cannot add the validator to the control array
of the table because it has to be form level to trigger
' but how can i make it render in this cell ?
'aCell.Controls.Add(custValRegularHours)
'aCell.Controls.Add(txtLDWRegularHoursRow)
End If

curRow.Cells.Add(aCell)
'TABLE ROW FOR TITLE**************************
End Sub

Apr 25 '07 #1
0 5269

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

Similar topics

13
2868
by: mr_burns | last post by:
hi, is it possible to change the contents of a combo box when the contents of another are changed. for example, if i had a combo box called garments containing shirts, trousers and hats, when...
1
3135
by: sleigh | last post by:
Hello, I'm building a web application that will build a dynamic form based upon questions in a database. This form will have several different sections that consist of a panel containing one to...
1
1348
by: psparago | last post by:
I have developed a tab user control in which each tab is itself a user control and the tab selection control is a datalist. Each tabbed user control has zero or more validator controls on it. The...
1
1945
by: Kum | last post by:
Hi, I need help in asp.net dynamic textbox controls validation. I am creating textbox controls dynamically on a asp.net webpage. Now after creating the textboxes on the page I want to validate...
1
2630
by: Nathan Sokalski | last post by:
When testing a form of mine which uses RequiredFieldValidators that have the Display property set to "Dynamic" the ErrorMessage property is automatically removed when an entry is completely typed...
3
1701
by: vodafone | last post by:
Hy all I've a little problem. I need to write a dynamic page that render control according to validation status return from previous control validation status. To be clear, I've page that...
3
1925
by: rgparkins | last post by:
Hi I am currently having problems with Validators in a user control. I am creating a wizard sign-up process which have the allocated step (hyperlinks" at the top of the page. A user can also...
4
4172
by: TS | last post by:
I am creating a User control and i create some dynamic controls in the init handler. one of the controls is a custom validator which i assign a serverValidate event handler. I usally always do my...
0
1533
by: Steve Funk | last post by:
All, I have searched all around and have not yet found the answer to this nor a solution. Hopfully it will be easy to overcome. Here is what I am trying to do: I'm trying to build a wizard...
0
7136
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,...
0
7018
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...
0
7232
jinu1996
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...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
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...
0
5490
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,...
0
3110
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...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.