Saturday, March 31, 2012

Strange Behavior from RequiredFieldValidator (and Two LinkButtons)

We have an ASP.NET web form with 1 TextBox, 2 LinkButtons, and 1
RequireFieldValidator. The situation is: the user needs to enter a folder
name in the TextBox and click the first LinkButton (the Create Folder
LinkButton) to create the folder. Then once that's done, they need to click
the second LinkButton (the Next LinkButton) to go to the next page (a
rudimentary wizard).

The RequiredFieldValidator is there to make sure the user enters a folder
name in the TextBox before clicking the first LinkButton (the Create Folder
LinkButton). This all works fine.

What's strange is if the user doesn't enter anything in the TextBox and
clicks the second LinkButton (the Next LinkButton) before clicking the first
LinkButton (the Create Folder LinkButton), the RequiredFieldValidator alarms
the error anyway.

Is this correct behavior? What we want is for the first LinkButton (the
Create Report LinkButton) only to validate that text has been entered in the
TextBox, not the second LinkButton (the Next LinkButton). How can we do
this?Hi JJ,

The function of the requiredfield validator is just to check the txtbox is
having some value or not.

If you want that checking has to be made only for the first link button and
not for the second link button, then specifically you have to inform the
validator as follows.

1. Click the second link button and go to the properties window.

2. Set the cause validation property to False.

So, here after when you are click second link button form will not do any
validations.

Hope this helps you.

Cheers,

Jerome. M

"JJ" wrote:

> We have an ASP.NET web form with 1 TextBox, 2 LinkButtons, and 1
> RequireFieldValidator. The situation is: the user needs to enter a folder
> name in the TextBox and click the first LinkButton (the Create Folder
> LinkButton) to create the folder. Then once that's done, they need to click
> the second LinkButton (the Next LinkButton) to go to the next page (a
> rudimentary wizard).
> The RequiredFieldValidator is there to make sure the user enters a folder
> name in the TextBox before clicking the first LinkButton (the Create Folder
> LinkButton). This all works fine.
> What's strange is if the user doesn't enter anything in the TextBox and
> clicks the second LinkButton (the Next LinkButton) before clicking the first
> LinkButton (the Create Folder LinkButton), the RequiredFieldValidator alarms
> the error anyway.
> Is this correct behavior? What we want is for the first LinkButton (the
> Create Report LinkButton) only to validate that text has been entered in the
> TextBox, not the second LinkButton (the Next LinkButton). How can we do
> this?
>

0 comments:

Post a Comment