Page Validation and Submit problems ??

N

Niks

Hi,

I am creating a simple .aspx page to add some fields with validation.

I have used different .NET validations like REquiredFieldValidator,
RegularExpressionValidator and showed the summary in the bulleted list
on top. I have 3 text boxes, and two RadioButtonList. and 3 buttons.
One for Submit, Reset and Exit.

If submit is pressed page should be validated and submit (insert into
DB) , Reset- page shoule be re-loaded, Exit - go to next page.

I have tried many options and i don't know which way is the best one.

a) when i submit the page .. all validatations are working perfect,
but how should i reset the page ? (again it is doing all the
validations ). I have used javascript too but for that i remove <%@
Page Language="vb" AutoEventWireup="false"
Codebehind="AddUsers.aspx.vb"%> then only it works. But i have to use
code behind and if remove this line for sake of JS i cannot use code
behind.

b) then i thought of using my own validations in function and for that
i believe if i use <asp:textbox and on click if of submit if i write
txtFullName.value does not work .. again i need to change every tag to
input type .. is this the only way.

Please suggest me the best way.

Code I am using is as follows :-


<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="AddUsers.aspx.vb"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script language="VB" runat="server">
Sub SubmitBtn_Click(sender As Object, e As EventArgs)
Response.write ("Arun Submit")
End Sub

Sub ResetBtn_Click(sender As Object, e As EventArgs)
Response.write ("Arun Reset")

End Sub

</script>


<title>AddModSysUsers</title>
<link href="incStyles.css" rel="stylesheet">
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table border="1" cellpadding="0" cellspacing="4" width="100%"
align="center">
<tr>
<td colspan="2" class="clsFont" align="middle">
<asp:panel runat="server" id="ValidationPanel" visible="false">
<asp:ValidationSummary ID="validSummary" runat="server"
HeaderText="Check the following fields:" DisplayMode="BulletList" />
</asp:panel>
</td>
</tr>
<tr>
<td colspan="2" align="middle" class="clsFont" height="30">
<font color="red">*</font>&nbsp;<B>Required</B>
</td>
</tr>
<tr>
<td class="clsFont" align="right" width="50%">
<font color="red">*</font>&nbsp;<B>Full Name(last, first) :</B>
&nbsp;
</td>
<td class="clsFont" align="left">
&nbsp;<asp:TextBox id="txtFullName" runat="server" Columns="30"
MaxLength="20"></asp:TextBox>
<asp:RequiredFieldValidator id="ValidateFullName"
ControlToValidate="txtFullName" ErrorMessage="Full Name must be filled
in" Display="None" runat="server"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="clsFont" align="right" width="50%">
<font color="red">*</font>&nbsp;<B>User Name (8-15 characters)
:</B> &nbsp;
</td>
<td class="clsFont" align="left">
&nbsp;<asp:TextBox id="txtUserName" runat="server" Columns="30"
MaxLength="15"></asp:TextBox>
<asp:RequiredFieldValidator id="validateUserName"
ControlToValidate="txtUserName" ErrorMessage="User Name must be filled
in" Display="None" runat="server"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator id="ValRegUserName"
ControlToValidate="txtUserName" ErrorMessage="User Name Should be in
8-15 Characters." ValidationExpression=".{8,15}" Display="None"
runat="server"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="clsFont" align="right">
<font color="red">*</font>&nbsp;<B>Password (8-15 characters)
:</B> &nbsp;
</td>
<td class="clsFont" align="left">
&nbsp;<asp:TextBox id="txtPassword" runat="server" Columns="30"
MaxLength="15"></asp:TextBox>
<asp:RequiredFieldValidator id="ValidatePassword"
ControlToValidate="txtPassword" ErrorMessage="Password must be filled
in" Display="None" runat="server"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator id="ValRegPassword"
runat="server" ControlToValidate="txtPassword" ErrorMessage="Password
Should be in 8-15 Characters." ValidationExpression=".{8,15}"
Display="None"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="clsFont" align="right">
<font color="red">*</font>&nbsp;<B>User Level :</B> &nbsp;
</td>
<td class="clsFont" align="left">
<ASP:RadioButtonList id="radUserLevel" RepeatLayout="Table"
runat="server" RepeatDirection="Horizontal" CssClass="clsFont">
<asp:ListItem>General</asp:ListItem>
<asp:ListItem>Omega</asp:ListItem>
<asp:ListItem>Super</asp:ListItem>
</ASP:RadioButtonList>
<asp:RequiredFieldValidator id="ValidateUserLevel"
runat="server" ControlToValidate="radUserLevel" ErrorMessage="User
Level must be selected. " Display="None"
InitialValue=""></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="clsFont" align="right">
<font color="red">*</font>&nbsp;<B>Status :</B> &nbsp;
</td>
<td class="clsFont" align="left">
<ASP:RadioButtonList id="radStatus" RepeatLayout="Table"
runat="server" RepeatDirection="Horizontal" CssClass="clsFont">
<asp:ListItem>Active&nbsp;&nbsp;</asp:ListItem>
<asp:ListItem>Inactive</asp:ListItem>
</ASP:RadioButtonList>
<asp:RequiredFieldValidator id="ValidateStatus" runat="server"
ControlToValidate="radStatus" ErrorMessage="Status must be selected. "
Display="None" InitialValue=""></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td align="middle" colspan="2">
&nbsp;&nbsp;
<asp:Button id="btnSubmit" Runat="server" text="Submit" OnClick
= "SubmitBtn_Click"></asp:Button>
&nbsp;&nbsp;
<asp:Button id="btnReset" runat="server" text="Reset" OnClick =
"ResetBtn_Click" ></asp:Button>
&nbsp;&nbsp;
<input type = "reset" id="Button1" runat="server" value="reset">
&nbsp;&nbsp;
<asp:Button id="btnExit" Runat="server" text="Exit Without
Saving"></asp:Button>
</td>
</tr>
</table>
</form>
</body>
</HTML>
 

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,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top