473,854 Members | 1,562 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 5300

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

Similar topics

13
2904
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 trousers and hats. when the user selects an option in the garment combo box, the options available...
1
3157
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 consists of a label for
1
1365
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), but only the tabbed user control which corresponds to the selected tab is marked as visible. This has...
1
1967
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 name as argument and returns an true if
1
2665
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 page is validated using the Page.Validate() method. I find this very weird (not to mention it may...
3
1713
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 so simple to do.
3
1945
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 page and load the control dynamically. All is sweet at the moment apart from the validation...
4
4211
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 would be initialized and have its event handlers set up, then after Load, the control would call its...
0
1553
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 seems to re-add every time a button or post back is initiated. Don't know if this is the problem.
0
9901
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
11024
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
10678
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 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...
0
9512
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
7914
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
7079
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
5940
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4153
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3185
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.