ASP application
prasath_s01 | Posted 10:39pm 5. June 2008 Server Time |
HI all
i m new to asp ... I m developing a model application in it ...
My requirement is .... I have two page sampe1.asp and sample2 .asp..
IN sample1 page i have to enter the details of a person like name and age if i click submit button here, it has to be redirected to sample2 .asp where i have to display the details entered in the first page....
I have two textbox in sample1.asp to to get the details....i have to do validation s for these text boxes
first one for getting "name "it should get only characters and max of 30 digits can be entered
the second one should get only integers max of two digits ..
onclick of submit button in sample1 the validation should occur
I have to Keep the details entered in the text box in session ...
IN sample2.asp i have two button one is back and another is enter ....
If i click the back button it should redirect to sampl1.asp where the value entered before should be there in the text box ....
if i click Enter button it should display a message "Success"
i have a tried something ...
Sampl1.asp
<html>
<%
Session("username")=Request.Form("fname")
Session("age")=Request.Form("fage")
name=Session("username")
age=Session("age")
Request.Form("fname")=name
Request.Form("fage")=age
End if
%>
<body>
<center>
<form name="test" method="post" action="sample2.asp">
<table>
<tr><td><b><h1>User Details </b></h1></td>
</tr>
</table>
<table>
<tr>
<td>
<b>Name</b></td><td>
<input type="text" name="fname" size="15" /></td></tr>
<tr>
<td>
<b>Age</b></td><td><input type="text" name="fage" size="15" /></td>
</tr>
</table>
<table>
<tr>
<td>
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
Sample2.asp
<html>
<body>
<%
Session("username")= request.form("fname")
Session("age")= request.form("fage")
%>
<center>
<table>
<tr><td><b><h1>User Information </b></h1></td>
</tr>
</table>
<table>
<tr>
<td>
<b>Name of the Person </b></td><td>
<% Response.write Session("username") %></td>
<tr>
<td>
<b>Age</b></td><td><% Response.write Session("age") %></td>
</tr>
</table>
<table>
<tr>
<td>
<input type="button" name="test" onclick="window.location.href='sampl1.asp'" value="Back">
</td>
<td>
<input type="button" name="test" value="Enter">
</td>
</tr>
</table>
</center>
</body>
</html>
Can any one help me pls .... I need to know how to do all the functionalities and validations
|
WizzKidd | Posted 12:06am 12. June 2008 Server Time |
It's probably best to use javascript to do the validation clientside so the data posted from sampl1.asp is validated before it even gets to sample2.asp
However if you want to do it server side, try putting this in sample2.asp (under the two lines of asp code)...
Session("errorMessage") = ""
strUsername = Session("username")
intAge = Session("age")
isError = False
If len(strUsername) = 0 Then
errorMessage = "Please Enter a Username"
isError = True
Else
Set re = New RegExp
re.Pattern = "^\w*$" '***this matches letters, numbers, and underscores
isAlphaNumeric = re.Test(strUsername)
If isAlphaNumeric Then
If len(strUsername) > 30 then
errorMessage = "Username must be less than 30 characters"
isError = True
End If
Else
errorMessage = "Username must use alphanumerics, eg. A-Z, a-z, 0-9 or _"
isError = True
End If
End If
If len(intAge) = 0 Then
errorMessage = "Please Enter an Age"
isError = True
Else
If isNumeric(intAge) Then
If intAge < 1 OR intAge > 99 then
errorMessage = "Age must be between 1 and 99 years"
isError = True
End If
Else
errorMessage = "Age must be a numeric, eg. 0-9"
isError = True
End If
End IF
If isError Then
Session("errorMessage") = errorMessage
Response.Redirect("sampl1.asp?errorfound=true")
End
and in sampl1.asp add the following as the first line:
If Request.Querystring("errorfound") = "true" Then
Response.Write("<scr" & "ipt>javscript:window.alert('" & Session("errorMessage") & "')</scr" & "ipt>")
End If
I've not tested the code, but that should do the error checking server side in the sample2.asp page
- Neil-One (aka WizzKidd)
- http://www.promotioncity.co.uk
Reply to Post ASP application
|
|
|