O, actually just now I tried with CustomValidator and it works fine!
However, it will only works correctly if there's only 1 (ONE)
validator for your form. Because when I tried to put that piece of
code (CustomValidator) into my form, which already contains
RequiredFieldValidators (for other textboxes), the CustomValidator
behaves strangely. This is the scenario:
For argument's sake, let's say I have textbox1 and checkboxlist1, and
also RequiredFieldValidator for textbox1, and CustomValidator for
checkboxlist1.
1. If I fill in the textbox1 and leave checkboxlist1 empty, and click
on submit button, CustomValidator works fine! (i.e. it will display
the ErrorMessage besides the checkboxlist1)
2. If I leave both (textbox1 and checkboxlist1 empty), ONLY the
RequiredFieldValidator displays the ErrorMessage besides textbox1. The
CustomValidator acts nothing!
Has anybody ever experiences this situation?
Thanks!
Adrian
--- In [EMAIL PROTECTED], Psychomaniac
<[EMAIL PROTECTED]> wrote:
> Yes! I got it! Thanks a lot!
> By the way, I tried to use RequiredFieldValidator for
> a checkboxlist, and it gives me error. I tried to
> search the net, and I actually found out that ASP.NET
> validator won't work with checkboxlist. Do you know a
> way to work around it?
>
> Thanks!
>
> Adrian
>
> --- Rajendra Appalla <[EMAIL PROTECTED]>
> wrote:
>
> > This is how we did it in our app.
> >
> > When we loop through the dataset to create controls
> > dynamically, we have
> > a flag too which tells us whether we need to add a
> > validator to the
> > control or not. If the flag says Y, then right after
> > the code that adds
> > the control to the form we add the validator code
> > and assign the ID of
> > the control just added above to the
> > ControlToValidate property of the
> > validator control.
> >
> > Here is an example:
> >
> > foreach(DataRow row in DataSet.Tables[0].Rows)
> > {
> >
> > if(row["ControlType"].ToString().Equals("textbox"))
> > {
> > TextBox tb = new TextBox();
> > tb.ID =
> > row["ControlID"].ToString();
> > this.Controls.Add(tb);
> >
> >
> > if(row{"IsRequired"].ToString().Equals("Y"))
> > {
> > RequiredFieldValidator rfv
> > = new
> > RequiredFieldValidator();
> > rfv.ControlToValidate =
> > row["ControlID"].ToString();
> > rfv.ErroMessage = "your
> > error message";
> > this.Controls.Add(rfv);
> > }
> > }
> > }
> >
> > Rajendra.
> >
> > -----Original Message-----
> > From: moron_psychomaniac
> > [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, September 16, 2004 5:02 AM
> > To: [EMAIL PROTECTED]
> > Subject: [AspNetAnyQuestionIsOk] Validator for
> > dynamically created
> > control
> >
> > I have just created a dynamic ASP.NET form. The
> > fields and its type
> > (textbox, checkbox, radiobutton, etc) are controlled
> > through the SQL
> > database.
> > Now I want to validate user-input by using the
> > validator provided by
> > ASP.NET. However, I can't really do it because all
> > my controls
> > (textbox, checkbox, etc) are created dynamically.
> > Here's a sample to the code for validator:
> >
> > <asp:RequiredFieldValidator id="valRequired"
> > runat="server"
> > ControlToValidate="textbox1"
> > ErrorMessage="* You must enter a value into
> > textbox1"
> > Display="dynamic">*
> > </asp:RequiredFieldValidator>
> >
> > Notice that it has a field "ControlToValidate". It
> > means I have to
> > specify the name of the control to be validated even
> > before the
> > control itself is even created.
> >
> > Anybody has a suggestion?
> > Thanks a lot!
> >
> >
> >
> >
> > Yahoo! Groups Sponsor
> > ADVERTISEMENT
> > click here
> >
> <http://us.ard.yahoo.com/SIG=129es87p2/M=298184.5285298.6392945.
3001176/
> >
> D=groups/S=1705006764:HM/EXP=1095411739/A=2352667/R=0/SIG=11t4iivpf/
*htt
> >
> p:/www.netflix.com/Default?mqso=60185359&partid=5285298>
> >
> >
> >
> <http://us.adserver.yahoo.com/l?M=298184.5285298.6392945.3001176/
D=group
> > s/S=:HM/A=2352667/rand=359831111>
> >
> > _____
> >
> > Yahoo! Groups Links
> > * To visit your group on the web, go to:
> > http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
> >
> > * To unsubscribe from this group, send an
> > email to:
> > [EMAIL PROTECTED]
> >
> <mailto:[EMAIL PROTECTED]
subject=Unsubs
> > cribe>
> >
> > * Your use of Yahoo! Groups is subject to
> > the Yahoo! Terms of
> > Service <http://docs.yahoo.com/info/terms/> .
> >
> >
> > [Non-text portions of this message have been
> > removed]
> >
> >
>
>
>
>
> _______________________________
> Do you Yahoo!?
> Declare Yourself - Register online to vote today!
> http://vote.yahoo.com
------------------------ Yahoo! Groups Sponsor --------------------~-->
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/