server side validation in form using panel controls

A

amessimon

Hi

I have a long form - around 80 fields - which i have decided to break up
into
more manageable sections using the <asp:panel> control.

Basically i have three panels (stages) containing various form elements
which i show
and as the user progresses through the form.

I need to use server side validation (client side is not an option) on some
of the fields in the form
dive used an <asp:RequiredFieldValidator> as an example here.

I cant seem to get the validation to take effect - you'll see the
<asp:RequiredFieldValidator> in <asp:panel Id="stage1">
as an example - if the user doesn't enter a value of some kind then i'd like
the same stage returned
not allowing the user to bypass it.

Thanks in advance...

Simon Ames

Here's the code.......

<script language="vb" runat="server">
Sub Page_load
fnHideAllPanels
If not IsPostback then
' show stage 1 on loading page for first time
stage1.Visible = True
End If
End Sub

Sub Button_Click (sender As System.Object, e As
system.Web.UI.WebControls.CommandEventArgs)
If e.CommandName = "move_to_stage_2" Then
If page.isvalid then
' if user has entered a value
stage2.Visible = True
Else
' if field is empty
stage1.Visible = True
End If
ElseIf e.CommandName = "move_to_stage_3" Then
stage3.Visible = True
ElseIf e.CommandName = "move_to_stage_1" Then
stage1.Visible = True
End If
End Sub

Function fnHideAllPanels
stage1.Visible = False
stage2.Visible = False
stage3.Visible = False
End Function
</script>

<form runat="server">
<asp:panel Id="stage1" RunAt="server" Wrap="">
<h2>Stage One</h2>
<asp:RequiredFieldValidator Id="val_username" RunAt="server"
ControlToValidate="username" EnableClientScript="false" Text="enter a
username" />
<asp:textbox id="username" runat="server"/> * required
<asp:Button Id="move_to_stage_2" CommandName="move_to_stage_2"
OnCommand="button_click" RunAt="server" Text="next"/>
</asp:panel>

<asp:panel Id="stage2" RunAt="server" Wrap="">
<h2>Stage Two</h2>
<asp:Button Id="move_to_stage_3" CommandName="move_to_stage_3"
OnCommand="button_click" RunAt="server" Text="next"/>
</asp:panel>

<asp:panel Id="stage3" RunAt="server" Wrap="">
<h2>Stage Three</h2>
<asp:Button Id="move_to_stage_1" CommandName="move_to_stage_1"
OnCommand="button_click" RunAt="server" Text="next"/>
</asp:panel>
</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top