hello
i see a web form that consists of three controls :textbox,requiredfieldvalidator that weired to the textbox and a button
within the click event of the button there is the following:
if page.isvalid then
response.redirect("Page is valid")
else
response.redirect("Page is not valid")
end if
according to my understandings:
when the user does not fill anything in the textbox and then clicks the button the the page will not be submitted (i.e no request to the page will be happened or no postback will be happened) then no server event will be happened so it is sure when the user submits the page so it will be valid so why the developer checks if the page is valid or not?
so i need to understand this topic
if any wrong in my understandings tell me please because i need to understand this concept
thank you for the help
![]() |
0 |
![]() |
That is slightly wrong. Unfortuantely the answer is not easy.
For ASP.NET 1.0 and 1.1
The javascript that is put onto the page to check its validity is only compatible with IE. This means that if you are using, e.g firefox, the javascript would not be put onto the page. The page would then postback even if the textbox was empty.
If you were using IE, then the page would not postback.
For ASP.NET 2.0
The javascript that is put onto the page to check its validity is meant to comform to the W3C standards, so should work on every browser. This means that no postback will occur.
For good web developing
No matter what happens, you should always do server side validation. Imagine if the user had javascript disabled.
Note:
I'm not sure, but I think ASP.NET 2.0 automatically does the server side validation for all controls except the custom control. Please correct me if I am wrong.
Jagdip
Intelligence is a burden.
Jagdip Singh Ajimal
Manchester (and yes, I am a Manchester United fan)
![]() |
0 |
![]() |
thank you for the support and for the help
![]() |
0 |
![]() |
Consider reading this article on the subject of common misunderstandings about validation: http://aspalliance.com/699.
--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
![]() |
0 |
![]() |
Hi Peter,
could you please clear something up for me.
In ASP.NET 2.0, lets say you have created a page with a requiredFieldValidatior on a textbox, and a button.
In the button's server side code, do you still need to check If Page.IsValid or does ASP.NET 2.0 now automatically do this for you?
i.e., do you write the same as ASP.NET 1.0/1.1:
Sub button1_click(....)handles button1.click
If Page.IsValid Then
......
End If
End Sub
or can you do:
Sub button1_click(.....)handles button1.click
'''''Validation automatically checked by ASP.NET 2.0 so dont need If clause
End Sub
Thanks
Jag
Intelligence is a burden.
Jagdip Singh Ajimal
Manchester (and yes, I am a Manchester United fan)
![]() |
0 |
![]() |
Hi,
in ASP.NET 2.0 you still have to make the if(Page.isValid) ...
in your example button1_click(.....) will fire if the user has JavaScript disabled, even if ASP.NET 2.0 do the server validation automatically.
the if(Page.isValid) statement allow you to customize what happens, stop executing code and write a message in a Label for example.
---
(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)
Laurent Duveau
Silverlight MVP
http://weblogs.asp.net/lduveau/
![]() |
0 |
![]() |
Hi Jag,
You still must test Page.IsValid. Microsoft did not add code to their Button's OnClick method to skip calling your Click event handler if IsValid is false.
--- Peter Blum
Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
www.PeterBlum.com
![]() |
0 |
![]() |