473,545 Members | 2,679 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.Tabl e control. I
dynamically create rows and add the cells on the fly
then at the end, call the WebControl.Tabl e 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 CreateChildCont rols()
'lots of line skipped to show only what matters
'---VALIDATORS---
If EditMode = True Then
custValRegularH ours = New CustomValidator
custValRegularH ours.EnableView State = False
custValRegularH ours.EnableClie ntScript = False
custValRegularH ours.Display = ValidatorDispla y.Dynamic
Controls.Add(cu stValRegularHou rs)

reqLDWRegularHo ursRow = New RequiredFieldVa lidator
reqLDWRegularHo ursRow.ControlT oValidate =
"txtLDWRegularH oursRow"
reqLDWRegularHo ursRow.Display =
ValidatorDispla y.Dynamic
reqLDWRegularHo ursRow.EnableCl ientScript = False
Controls.Add(re qLDWRegularHour sRow) 'add validator to
control array of user control.

'---STYLE SHEET---
If ValidatorCSSCla ss <String.Empty Then
custValRegularH ours.CssClass = ValidatorCSSCla ss
reqLDWRegularHo ursRow.CssClass = ValidatorCSSCla ss
End If
End If

End Sub

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

RenderLWEarning sTableBeginTag( writer)
RenderLWEarning sTitleLabelRow( writer)
RenderLblLWEarn ingsDaysLabelRo w(writer)
RenderLWEarning sDateDataRow(wr iter)
RenderLWEarning sRegHoursDataRo w(writer)
End Sub

'*** <Table>
Protected Sub RenderLWEarning sTableBeginTag( ByVal output As
System.Web.UI.H tmlTextWriter)
'<table>
output.AddAttri bute(HtmlTextWr iterAttribute.C ellspacing,
"0")
output.AddAttri bute(HtmlTextWr iterAttribute.C ellpadding,
"2")
output.AddAttri bute(HtmlTextWr iterAttribute.W idth, "400")
output.AddAttri bute(HtmlTextWr iterAttribute.B order, "0")
output.RenderBe ginTag(HtmlText WriterTag.Table )
End Sub

'*** TITLE
Protected Sub RenderLWEarning sTitleLabelRow( ByVal output As
System.Web.UI.H tmlTextWriter)
'- TABLE ROW FOR TITLE********** *************** *
'<tr>
output.RenderBe ginTag(HtmlText WriterTag.Tr)
'<td>
If EditMode = False Then
output.AddAttri bute(HtmlTextWr iterAttribute.C olspan,
"9")
Else
output.AddAttri bute(HtmlTextWr iterAttribute.C olspan,
"8")
End If
output.RenderBe ginTag(HtmlText WriterTag.Td)
output.Write("< span class=bigred>*</span>&nbsp;")
lblTitle.Render Control(output)
If EditMode = True Then
output.Write("& nbsp;")

'Render the validators at the appropriate area in the table

reqLDWRegularHo ursRow.RenderCo ntrol(output)
custValRegularH ours.RenderCont rol(output)

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

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

Protected Overrides Sub CreateChildCont rols()
'---VALIDATORS---
If EditMode Then
custValRegularH ours = New CustomValidator
custValRegularH ours.EnableView State = False
custValRegularH ours.EnableClie ntScript = False
custValRegularH ours.Display = ValidatorDispla y.Dynamic
Controls.Add(cu stValRegularHou rs)

reqLDWRegularHo ursRow = New RequiredFieldVa lidator
reqLDWRegularHo ursRow.ControlT oValidate =
"txtLDWRegularH oursRow"
reqLDWRegularHo ursRow.Display = ValidatorDispla y.Dynamic
reqLDWRegularHo ursRow.EnableCl ientScript = False
Controls.Add(re qLDWRegularHour sRow)

'---STYLE SHEET---
If ValidatorCSSCla ss <String.Empty Then
custValRegularH ours.CssClass = ValidatorCSSCla ss
reqLDWRegularHo ursRow.CssClass = ValidatorCSSCla ss
End If
End If
End Sub

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

LWETable = New Table

RenderLWEarning sTableBeginTag( ) 'instantiate table, create
all rows
RenderLWEarning sTitleLabelRow( ) 'question
RenderLblLWEarn ingsDaysLabelRo w() 'headers
RenderLWEarning sDateDataRow() 'Dates
RenderLWEarning sRegHoursDataRo w() 'Hours

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

End Sub

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

LWETable.Attrib utes.Add("cellp adding", "0")
LWETable.Attrib utes.Add("cells pacing", "0")
LWETable.Attrib utes.Add("borde r", "0")
LWETable.Attrib utes.Add("width ", "495")

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

If DaysOfWeek.Coun t = 0 Then
SetDayArray()
End If

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

lblDays.ID = strDaysOfWeekDi splay.Item(i)
lblDays.Text = strDaysOfWeekDi splay.Item(i)

aLabel = QuickClone(lblD ays)
' 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(aC ell)
Next

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

LWETable.Rows(T ableRows.Footer ).Cells.Add(aCe ll)
End If
End Sub

'*** TITLE
Protected Sub RenderLWEarning sTitleLabelRow( )
Dim curRow As TableRow = LWETable.Rows(T ableRows.Title)
Dim aCell As TableCell
'- TABLE ROW FOR TITLE********** *************** *
'<td>
aCell = New TableCell
If EditMode = False Then
aCell.ColumnSpa n = 3
Else
aCell.ColumnSpa n = 3
End If
Dim aSpan As HtmlGenericCont rol = New
HtmlGenericCont rol("span")
aSpan.InnerText = "*"
aSpan.Attribute s.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(custValReg ularHours)
'aCell.Controls .Add(txtLDWRegu larHoursRow)
End If

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

Apr 25 '07 #1
0 5274

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

Similar topics

13
2870
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 the user selects shirts another combo box called 'size' would contain sizes in relation to shirts (ie. chest/neck size). the same would occur for...
1
3138
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 many questions. To keep it simple, I'll describe the basics of what I'm trying to design. I've created a TextBox composite control that...
1
1351
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 hosting page has a summary validator on it. Each tabbed user control is created dynamically on page_init (on both postback and not postback),...
1
1946
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 these text boxes when the user submits or posts back to the server. My intention was to create a textboxvalidator function which takes the control...
1
2640
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 and the user leaves the textbox. However, if the entry is selected from the list of previously typed entries, the error does not disappear until the...
3
1703
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 starts requesting some info, then user press a button, and the same page should show the new field only if validation returns true. But it sounds not...
3
1929
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 click next/previous. Dependant on the current step in the sign-up process I am loading a new user control as I dont want to have 7-8 pages, just one...
4
4178
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 controls as custom server controls and don't understand why this event won't fire. I figured if the creation of the control was in the init, it...
0
1540
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 form completely dynamic. I'm adding the labels, textboxes, drop downs, radio buttons, etc dynamically. I am able to add them via Page Init. Which...
0
7428
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...
0
7685
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. ...
1
7452
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7784
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...
0
5071
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...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
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 we have to send another system
1
1039
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
738
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...

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.