Validating TextBoxes

  • Thread starter Thread starter clintonG
  • Start date Start date
C

clintonG

I have to get to this later tonight or tommorrow...and wonder...

There's two TextBoxes in a Wizard Step posing an either-or situtation. Only
one or the other TextBox may pass data. The application also uses
MasterPages.

Which tactic would you implement for the required validation when there's
two textboxes but only one may contain data? Any blogs on this? So far
search terms return nebulous results as my terms are apparently too
ambiguous.
 
It wouldn't be a RequiredFieldValidator, it would be a CustomValidator and
you'd write your own if/then logic.
 
Good tip thank you for the snappy reply. I haven't had to use a Custom
Validator yet and was thinking I might need another I haven't had any
experience with yet; the ValidatorGroup (but no).
 
Your scenario would be pretty simple:

<SCRIPT LANGUAGE="JavaScript">

function testFields(source, args)
{
if(txtField1.value == "" && txtField2.value == "")
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}

</SCRIPT>
 
Hey that was nice of you but I'll work this aspect of the code out myself as
there's a bit more to it noting the following rules just for starters:

* Both TextBoxes empty? (one must be populated)
* Both populated? (only one may be populated)
* Valid input in the TextBox? (one must be an email address the other must
be an alphanumeric name)

However, it would be helpful of you know how to identify which of the
LinkButtons generated by a DataList were used to display the set of
TextBoxes we have been talking about. The 2.0 Wizard control requires the
items generated by the DataList to inherit from IButtonControl which
supports a Text property I need to reference.

I'm googling...and deep into the doo at msdn2.microsoft.com working on the
answer and hey, I appreciate your comments...

--
<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h
 
Hi Clinton,

It's been a long time since I've used a DataList and I'm still using VS.NET
2003, but I know that when working with DataGrid's, if you want to gain
access to the items that are on a row of the grid you work with the "e.Item"
argument of the specific event you are dealing with. If you have set up
these textboxes as templates and have given them ID's, you could use
"e.Item.FindControl(controlName)" to locate the control.

-Good luck!
 
When using 2.0 the compiler renames control IDs to manage the control
hierarchy during the page lifecycle. I haven't got my head around this
context for client-side referencing yet. Part of the problem is the fact
that 2.0 obfuscates the identification of controls. Furthermore, as you will
see below, the name of the controls generated by the DataList is
"SideBarButton" so I have to somehow learn how to access the control's Text
property.

Trace shows the examples below of delineated results from the control tree
hierarchy. Be aware of this when you "move up" to 2.0. Thanks though Scott.
Later...

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h

// Trace output from Wizard Control DataList SideBar.
// LinkButtons (IButtonControl) generated by the DataList in Wizard control
SideBar -- note -- the ctlXXX value changes for each control generated and a
generic name of "SideBarButton" is used to identify what is actually a
LinkButton.
// Both ID types return the same value delineated differently. Only ClientID
can be used with JavaScript
[1.a] Using UniqueID:
ctl00$CenterPanelContent$ChannelBuilderWizard$SideBarContainer$SideBarList$ctl00$SideBarButton
[1.b] Using UniqueID:
ctl00$CenterPanelContent$ChannelBuilderWizard$SideBarContainer$SideBarList$ctl01$SideBarButton
[2.a] Using ClientID:
ctl00_CenterPanelContent_ChannelBuilderWizard_SideBarContainer_SideBarList_ctl00_SideBarButton
[2.b] Using ClientID:
ctl00_CenterPanelContent_ChannelBuilderWizard_SideBarContainer_SideBarList_ctl01_SideBarButton
 
Are you using templates while designing this DataList control?


clintonG said:
When using 2.0 the compiler renames control IDs to manage the control
hierarchy during the page lifecycle. I haven't got my head around this
context for client-side referencing yet. Part of the problem is the fact
that 2.0 obfuscates the identification of controls. Furthermore, as you
will see below, the name of the controls generated by the DataList is
"SideBarButton" so I have to somehow learn how to access the control's
Text property.

Trace shows the examples below of delineated results from the control tree
hierarchy. Be aware of this when you "move up" to 2.0. Thanks though
Scott. Later...

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h

// Trace output from Wizard Control DataList SideBar.
// LinkButtons (IButtonControl) generated by the DataList in Wizard
control SideBar -- note -- the ctlXXX value changes for each control
generated and a generic name of "SideBarButton" is used to identify what
is actually a LinkButton.
// Both ID types return the same value delineated differently. Only
ClientID can be used with JavaScript
[1.a] Using UniqueID:
ctl00$CenterPanelContent$ChannelBuilderWizard$SideBarContainer$SideBarList$ctl00$SideBarButton
[1.b] Using UniqueID:
ctl00$CenterPanelContent$ChannelBuilderWizard$SideBarContainer$SideBarList$ctl01$SideBarButton
[2.a] Using ClientID:
ctl00_CenterPanelContent_ChannelBuilderWizard_SideBarContainer_SideBarList_ctl00_SideBarButton
[2.b] Using ClientID:
ctl00_CenterPanelContent_ChannelBuilderWizard_SideBarContainer_SideBarList_ctl01_SideBarButton



Scott M. said:
Hi Clinton,

It's been a long time since I've used a DataList and I'm still using
VS.NET 2003, but I know that when working with DataGrid's, if you want to
gain access to the items that are on a row of the grid you work with the
"e.Item" argument of the specific event you are dealing with. If you
have set up these textboxes as templates and have given them ID's, you
could use "e.Item.FindControl(controlName)" to locate the control.

-Good luck!
 
Yes, I've templated the Wizard control. A DataList must be used in a
SideBar template. The controls generated by the DataList must inherit from
IButtonControl which supports a Text property. I chose to use LinkButtons in
the DataList.

As noted you can see in the Trace snippet I posted previously. The compiler
renames the LinkButtons as SideBarButton. The image in this document [1]
shows what a rendered Wizard looks like and is a good visual reference as
the containers the Wizard is made of are labeled with callouts. See how the
SideBar tempate contains a list of items?

In this context I don't know how to reference the Text property of a control
that is inherited from IButtonControl. If I could figure out how to
reference the Text property of the LinkButtons rendered in the SideBar I
wouldn't need to care about all the LinkButtons being named SideBarButton in
the control tree hierarchy.

In fact, -- somehow -- I have to reference the Text property -- as I think
you too will be compelled to agree. Consider the fact that the Wizard
exposes two ways for a user to leave the Step (labeled as the View by [1]).
That Step displays the two TextBoxes we have been discussing. When moving to
the next step (or a previous step) the user may choose to select the Next
button or the user may choose to select some other LinkButton list item in
the SideBar. I will need to reference the Text property of the list items to
determine what has and has not been selected from the SideBar.

I've burned out on googling for IButtonControl and am going to peruse the
asp.net forums tonight. Glad to see you hanging in here. Good for you to
prepare for the evils of 2.0 :-)

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/

[1] http://msdn.microsoft.com/msdnmag/issues/04/11/CuttingEdge/



Scott M. said:
Are you using templates while designing this DataList control?


clintonG said:
When using 2.0 the compiler renames control IDs to manage the control
hierarchy during the page lifecycle. I haven't got my head around this
context for client-side referencing yet. Part of the problem is the fact
that 2.0 obfuscates the identification of controls. Furthermore, as you
will see below, the name of the controls generated by the DataList is
"SideBarButton" so I have to somehow learn how to access the control's
Text property.

Trace shows the examples below of delineated results from the control
tree hierarchy. Be aware of this when you "move up" to 2.0. Thanks
though Scott. Later...

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h

// Trace output from Wizard Control DataList SideBar.
// LinkButtons (IButtonControl) generated by the DataList in Wizard
control SideBar -- note -- the ctlXXX value changes for each control
generated and a generic name of "SideBarButton" is used to identify what
is actually a LinkButton.
// Both ID types return the same value delineated differently. Only
ClientID can be used with JavaScript
[1.a] Using UniqueID:
ctl00$CenterPanelContent$ChannelBuilderWizard$SideBarContainer$SideBarList$ctl00$SideBarButton
[1.b] Using UniqueID:
ctl00$CenterPanelContent$ChannelBuilderWizard$SideBarContainer$SideBarList$ctl01$SideBarButton
[2.a] Using ClientID:
ctl00_CenterPanelContent_ChannelBuilderWizard_SideBarContainer_SideBarList_ctl00_SideBarButton
[2.b] Using ClientID:
ctl00_CenterPanelContent_ChannelBuilderWizard_SideBarContainer_SideBarList_ctl01_SideBarButton



Scott M. said:
Hi Clinton,

It's been a long time since I've used a DataList and I'm still using
VS.NET 2003, but I know that when working with DataGrid's, if you want
to gain access to the items that are on a row of the grid you work with
the "e.Item" argument of the specific event you are dealing with. If
you have set up these textboxes as templates and have given them ID's,
you could use "e.Item.FindControl(controlName)" to locate the control.

-Good luck!

message Hey that was nice of you but I'll work this aspect of the code out
myself as there's a bit more to it noting the following rules just for
starters:

* Both TextBoxes empty? (one must be populated)
* Both populated? (only one may be populated)
* Valid input in the TextBox? (one must be an email address the other
must be an alphanumeric name)

However, it would be helpful of you know how to identify which of the
LinkButtons generated by a DataList were used to display the set of
TextBoxes we have been talking about. The 2.0 Wizard control requires
the items generated by the DataList to inherit from IButtonControl
which supports a Text property I need to reference.

I'm googling...and deep into the doo at msdn2.microsoft.com working on
the answer and hey, I appreciate your comments...

--
<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h




Your scenario would be pretty simple:

<SCRIPT LANGUAGE="JavaScript">

function testFields(source, args)
{
if(txtField1.value == "" && txtField2.value == "")
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}

</SCRIPT>

message Good tip thank you for the snappy reply. I haven't had to use a
Custom Validator yet and was thinking I might need another I haven't
had any experience with yet; the ValidatorGroup (but no).

--
<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/


It wouldn't be a RequiredFieldValidator, it would be a
CustomValidator and you'd write your own if/then logic.


message I have to get to this later tonight or tommorrow...and wonder...

There's two TextBoxes in a Wizard Step posing an either-or
situtation. Only one or the other TextBox may pass data. The
application also uses MasterPages.

Which tactic would you implement for the required validation when
there's two textboxes but only one may contain data? Any blogs on
this? So far search terms return nebulous results as my terms are
apparently too ambiguous.

--
<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP
http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h
 
Back
Top