PDA

View Full Version : Please help:Required Field Validator


justnew
04-04-2005, 10:03 PM
I have a login page with txtbox1 for username and txtbox2 for password. I have Required_Field_Validator for both textboxes. In my local webserver it fuctionn correctly. But when I upload the page to the webserver it will not work correctly. when I click the login button it just proceed to the targeted page. but if I have enter username without password and when I click on the login button then the Required field validator shows that the field required data.
Any Idea of what is going on?

BigPete
04-04-2005, 10:49 PM
could we see some code please?

justnew
04-04-2005, 11:36 PM
Public Function GetUserPass(ByVal Email As String, ByVal UserPwd As String) As Boolean
sql = "select UserPwd from Seller where Email = '" & Email & "'"
Dim connString As String = "Server=myserver; Initial Catalog=mydb; UID=myuid; Password=mypwd; Network Library=dbmssocn;"

Dim conn As SqlConnection = New SqlConnection(connString)
Dim da As SqlDataAdapter = New SqlDataAdapter(sql, conn)
Dim ds As DataSet = New DataSet
conn.Open()
Try
da.Fill(ds, "Seller")
If ds.Tables(0).Rows.Count > 0 Then
If ds.Tables(0).Rows(0).Item(0) = UserPwd Then
Return True
Else
Return False
End If
End If
Catch e As SqlException


Throw (e)

Finally
'rydd opp
conn.Close()
End Try
End Function



Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
Dim ok as boolean
ok = GetUserPass(txtemail.Text, txtpwd.Text)
If ok Then

Response.Redirect("http:\\www.mywebsite.com\LoginUser.aspx")
Else
lblloginF.Visible = True
End If
End Su

BigPete
04-05-2005, 03:53 AM
you know, you could always just use javascript validation.

tboss132
04-05-2005, 09:10 AM
Yeah, javascript is better for client-side validation.

It is run by the client's machine and not your server
It is faster cos the page isn't sent anywhere to be validated
Other reasons i can't think of in a hurry.

justnew
04-05-2005, 08:14 PM
Show how to do that with Java script. Thanks in advance

chud_wallice
04-05-2005, 09:35 PM
<script type="text/JavaScript">
<!--
function CheckPasswords()
{
if (document.FormName.Password1.value != document.FormName.Password2.value)
{
alert ("Your passwords do not match. Please Check them \n and try again.");
return false;
}
else
return true;
}
-->
</script>


and to your form tag add

onsubmit="return CheckPasswords()"



hth

tboss132
04-05-2005, 09:38 PM
You find more ways to control forms with javascript here (http://www.dynamicdrive.com/dynamicindex16/)

glenngv
04-06-2005, 06:04 AM
Yeah, javascript is better for client-side validation.

It is run by the client's machine and not your server
It is faster cos the page isn't sent anywhere to be validated
Other reasons i can't think of in a hurry.

Sure, but as a rule of thumb, you should also validate on the server-side and not totally rely on javascript.

Javascript can be easily disabled.
Javascript can be easily bypassed.
Server-side validation can't be disabled and bypassed.

So you should have both. It may be redundant but that makes it more secure.

tboss132
04-06-2005, 10:26 AM
Well that's true, people could always bypass javascript. It's good to have validation on both client and server.

justnew
04-07-2005, 11:41 PM
Thanks to you all for the tips. Is ok now

BigPete
04-08-2005, 02:58 AM
Sure, but as a rule of thumb, you should also validate on the server-side and not totally rely on javascript.

Javascript can be easily disabled.
Javascript can be easily bypassed.
Server-side validation can't be disabled and bypassed.

So you should have both. It may be redundant but that makes it more secure.
The way i set up my Javascript validation is such that after you validate it, the Javascript actually does the submitting of the form. To edit the code previously submitted . . .
<script type="text/JavaScript">
<!--
function CheckPasswords()
{
if (document.FormName.Password1.value != document.FormName.Password2.value)
{
alert ("Your passwords do not match. Please Check them \n and try again.");
return false;
}
else
document.formname.submit();
}
-->
</script>
Something simple like that will ensure that if they don't have Javascript enabled, you can't submit the form.

glenngv
04-08-2005, 03:19 AM
Something simple like that will ensure that if they don't have Javascript enabled, you can't submit the form.
That's not good. Javascript in this case just serves as a validation tool. If it's not available, the user should still be able to use the form.

And even though javascript is enabled, I can still submit the form even without calling CheckPasswords() function or any setup validation function for that matter.

tboss132
04-14-2005, 09:13 PM
I can still submit the form even without calling CheckPasswords() function or any setup validation function for that matter.
Sorry to bring up this thread again but hey Glenn, how do you do that?

miranda
04-14-2005, 10:09 PM
RequiredFieldValidator's in ASP.NET do use javascript. In order for the validation to work the aspnet_client directory needs to be in place. You probably have it on your local machine but it was never installed on the server.

In response to TBoss132 all you have to do is disable javascript in your web browser. Then all javascript functions are bypassed.

glenngv
04-15-2005, 03:46 AM
Sorry to bring up this thread again but hey Glenn, how do you do that?
To add to what miranda said about this, you can also bypass validation even if javascript is not turned off. If the validation is done onsubmit, you can just type this in the address bar to nullify onsubmit.

javascript:document.forms[0].onsubmit=null;void(0);


If the validation is done on a normal button's onclick, you can change the onclick handler.

javascript:document.forms[0].theButton.onclick=document.forms[0].submit;void(0);