PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

Do I have to call Page.Validate on server side for val controls?

 
 
TS
Guest
Posts: n/a
 
      23rd Mar 2004
If I have a required field validator for instance, does it require any
server side code to make it validate on server?
I'm not sure if this is called by default, or if I need to call this on my
page, and wrap all my code within this if block.


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      23rd Mar 2004
no. server validation is run when you call Page.IsValid

-- bruce (sqlwork.com)


"TS" <(E-Mail Removed)> wrote in message
news:ueSJi$(E-Mail Removed)...
> If I have a required field validator for instance, does it require any
> server side code to make it validate on server?
> I'm not sure if this is called by default, or if I need to call this on my
> page, and wrap all my code within this if block.
>
>



 
Reply With Quote
 
 
 
 
TS
Guest
Posts: n/a
 
      23rd Mar 2004
so I have to query page.isvalid on every posted back page, and only process
the page if this test succeeds

"bruce barker" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> no. server validation is run when you call Page.IsValid
>
> -- bruce (sqlwork.com)
>
>
> "TS" <(E-Mail Removed)> wrote in message
> news:ueSJi$(E-Mail Removed)...
> > If I have a required field validator for instance, does it require any
> > server side code to make it validate on server?
> > I'm not sure if this is called by default, or if I need to call this on

my
> > page, and wrap all my code within this if block.
> >
> >

>
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      24th Mar 2004
Hi TS,

As Bruce has mentioned, the ASP.NET will call all the validation
controls(if enabled)'s validation on the page before the page's post back
eventhandler is executed. So if you want to execute some certain operations
only when the page is validatored , you can add the following code in your
event handler:
private void btnSubmit_Click(object sender, System.EventArgs e)
{

if(Page.IsValid)
{
//... your code
}
}

#notice that you should not call "Page.IsValid" property before a certain
server control's post back event handler(such as in page_load or page_Init
). Because the page's serverside validation hasn't been completed at that
time, if you try accessing the IsValid propery in those event, you 'll get
exceptions.

In addtion, the validator controls by default has
"EnabledClientScript=true" which means the page need to be validated at
clientside before it is postedback. If not valid, it won't be posted back.
So I think you can also use the clientside validation to ensure that when a
page is posted back, it has been valid.

And here are two good tech articles on detailed description of the ASP.NET
validaor control's mechanism and useage:
#ASP.NET Validation in Depth
http://msdn.microsoft.com/library/en...id.asp?frame=t
rue#aspplusvalid_serverside

#Validating ASP.NET Server Controls
http://msdn.microsoft.com/library/en...idateaspnetser
vercontrols.asp?frame=true

Hope they also helpful.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


 
Reply With Quote
 
TS
Guest
Posts: n/a
 
      24th Mar 2004
On the examples, the only time a call to page.IsValid is in customValidator
examples. So to make this crystal clear, if someone bypasses my form or has
JS disabled, and enters invalid data, if I don't call to page.isvalid, and
just process the page normally, the page will still process?

If this is so, then don't you agree that to be secure and to catch any
possible exceptions that may occur when using bad data, you should always
make a call to page.IsValid before you do anything with the data that was
entered, such as stick in a db?

"Steven Cheng[MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi TS,
>
> As Bruce has mentioned, the ASP.NET will call all the validation
> controls(if enabled)'s validation on the page before the page's post back
> eventhandler is executed. So if you want to execute some certain

operations
> only when the page is validatored , you can add the following code in your
> event handler:
> private void btnSubmit_Click(object sender, System.EventArgs e)
> {
>
> if(Page.IsValid)
> {
> //... your code
> }
> }
>
> #notice that you should not call "Page.IsValid" property before a certain
> server control's post back event handler(such as in page_load or page_Init
> ). Because the page's serverside validation hasn't been completed at that
> time, if you try accessing the IsValid propery in those event, you 'll get
> exceptions.
>
> In addtion, the validator controls by default has
> "EnabledClientScript=true" which means the page need to be validated at
> clientside before it is postedback. If not valid, it won't be posted back.
> So I think you can also use the clientside validation to ensure that when

a
> page is posted back, it has been valid.
>
> And here are two good tech articles on detailed description of the ASP.NET
> validaor control's mechanism and useage:
> #ASP.NET Validation in Depth
>

http://msdn.microsoft.com/library/en...id.asp?frame=t
> rue#aspplusvalid_serverside
>
> #Validating ASP.NET Server Controls
>

http://msdn.microsoft.com/library/en...idateaspnetser
> vercontrols.asp?frame=true
>
> Hope they also helpful.
>
> Regards,
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
> Get Preview at ASP.NET whidbey
> http://msdn.microsoft.com/asp.net/whidbey/default.aspx
>
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      25th Mar 2004
Hi TS,

Thanks for your followup. Yes, the user many use disabling client side
script to bypass the client validation. Thus, we may need to call the
Page's "Page.Validate()" function to instructure all the validator controls
work and then in post back event
check the Page.IsValid to ensure the page is valid or not. So the user is
able to by pass the client script validation but not able to hack the
serverside operations if we add the validaion check. Do you think so?

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

 
Reply With Quote
 
TS
Guest
Posts: n/a
 
      30th Mar 2004
thanks

"Steven Cheng[MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi TS,
>
> Thanks for your followup. Yes, the user many use disabling client side
> script to bypass the client validation. Thus, we may need to call the
> Page's "Page.Validate()" function to instructure all the validator

controls
> work and then in post back event
> check the Page.IsValid to ensure the page is valid or not. So the user is
> able to by pass the client script validation but not able to hack the
> serverside operations if we add the validaion check. Do you think so?
>
> Regards,
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
> Get Preview at ASP.NET whidbey
> http://msdn.microsoft.com/asp.net/whidbey/default.aspx
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if val in col3 is one of 13 codes (list), apply factor to val in c PBcorn Microsoft Excel Worksheet Functions 1 29th Jul 2008 12:12 PM
check cell val, increment val =?Utf-8?B?REpT?= Microsoft Excel Worksheet Functions 0 30th Jan 2006 11:29 PM
Using Side-by-Side Calendars, would like side-by-side DAYS Matt Landis Microsoft Outlook Calendar 6 19th Mar 2004 10:49 AM
How to call server side (VB/C#) function from client side (Javascript)? =?Utf-8?B?ZGR0?= Microsoft ASP .NET 3 12th Mar 2004 11:01 AM
Call server side code from client side Borr Microsoft ASP .NET 3 10th Nov 2003 03:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:12 PM.