471,582 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,582 software developers and data experts.

Custom control validation

I have created a custom control. It has:
-list of textboxes
-list of dropdownlists.
I want to use a custom validator to perform some validation, but
somehow I can't fo it. The code looks like this:

public class ColumnSelector : Panel
public TextBox[] textBoxes;
public DropDownList[] lists;
CustomValidator validator;
Label label;
Button button;

public ColumnSelector(int numberOfColumns, string[] values)
//initializing textboxes etc.
validator = new CustomValidator();
validator.ErrorMessage = "You must choose a different value for
each column";
validator.ControlToValidate = lists[0].ID;
validator.Display = ValidatorDisplay.Dynamic;//?

for (int i = 0; i < number; i++)
for (int i = 0; i < number; i++)

protected void validator_ServerValidate(object source,
ServerValidateEventArgs args)
//validation here
//if ok args.IsValid = true;
//else args.IsValid = false;

protected void button_Click(object sender, EventArgs e)

This control was created without using GUI so maybe I have forgotten
something? (linking validator to the textbox?). Please let me know
what's wrong with it.

There is also some other problem, that looks like a bug to me, but
maybe it isn't...
I want all of the dropdownlists to have different selectedindex value
initially (unless there's more dropdownlists than values), but somehow
they all have the same value (the value of the last dropdownlist
selected index actually).

ListItem[] items = new ListItem[listOfItems];
for (int i = 0; i < values.Length; i++)
items[i] = new ListItem(values[i]);

for (int i = 0; i < number; i++)
lists[i] = new DropDownList();
if (i < values.Length) lists[i].SelectedIndex = i;
else lists[i].SelectedIndex = values.Length - 1;

Is it a bug or my error somewhere?


Dec 27 '06 #1
0 1453

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Pham Nguyen | last post: by
5 posts views Thread by | last post: by
reply views Thread by Marek | last post: by
3 posts views Thread by Andy | last post: by
1 post views Thread by rn5a | last post: by
reply views Thread by rn5a | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

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.