PC Review


Reply
Thread Tools Rate Thread

Different validation of data

 
 
jeeji
Guest
Posts: n/a
 
      5th Aug 2008
Hi

I have a web application that has a main page in which the user inputs
some data in some input fields.
The page contains two buttons (Button1 and Button2) that do a
postback.
When Button1 is clicked I want to call a function called Validate1(),
and when Button2 is clicked I want to call Validate2(). Those
functions validate the data input in the input fields.
If data is not valid I want to mark the input field that caused the
datavalidation error.

What is the best practice way of doing this.
My problem is that when a button is clicked, page_load() is called
first, followed by the button click event handler.
I cannot put the calls to Validate1() or Validate2() in page_load,
because I cannot see which button was clicked.
But then, page_load typically draws the page to be rendered. But in
order to render the page, I have to know which input field caused the
validation error.

I would assume this is a typical scenario, which I cannot seem to
figure out.

Thanks in advance
Jeeji
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      6th Aug 2008
Hi,

place the calls to respective button click event handlers. Handler of
Button1's click calls Validate1, and Handler of Button2 calls Validate2.

The logic in Page_Load could probably be in !Page.IsPostBack check when it
wouldn't cause any issues on postback (e.g with IsPostBack check you can
place logic in Page_load which is run only on initial request but not on
portback anymore)

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"jeeji" <(E-Mail Removed)> wrote in message
news:d3cb245c-c145-42a4-9820-(E-Mail Removed)...
> Hi
>
> I have a web application that has a main page in which the user inputs
> some data in some input fields.
> The page contains two buttons (Button1 and Button2) that do a
> postback.
> When Button1 is clicked I want to call a function called Validate1(),
> and when Button2 is clicked I want to call Validate2(). Those
> functions validate the data input in the input fields.
> If data is not valid I want to mark the input field that caused the
> datavalidation error.
>
> What is the best practice way of doing this.
> My problem is that when a button is clicked, page_load() is called
> first, followed by the button click event handler.
> I cannot put the calls to Validate1() or Validate2() in page_load,
> because I cannot see which button was clicked.
> But then, page_load typically draws the page to be rendered. But in
> order to render the page, I have to know which input field caused the
> validation error.
>
> I would assume this is a typical scenario, which I cannot seem to
> figure out.
>
> Thanks in advance
> Jeeji



 
Reply With Quote
 
jeeji
Guest
Posts: n/a
 
      13th Aug 2008
Thanks for you answer,
So you are saying that I should build my controls and mark the fields
in the button handler functions?
For some reason that does not look best practic like.
So my page:load should have a call to BuildControls() in an
if (! IsPostBack) block, and otherwise the BuildControls(errorField)
should be in the button handler functions.


Please tell me if you are sure that this is best practice. I find the
logic with ASP.Net hard to understand. Not that it is badly
structured, I just think that my mind is not set to understand it.

Thanks again
Jihad


On 6 Aug., 18:30, "Teemu Keiski" <jot...@aspalliance.com> wrote:
> Hi,
>
> place the calls to respective button click event handlers. Handler of
> Button1's click calls Validate1, and Handler of Button2 calls Validate2.
>
> The logic in Page_Load could probably be in !Page.IsPostBack check when it
> wouldn't cause any issues on postback (e.g with IsPostBack check you can
> place logic in Page_load which is run only on initial request but not on
> portback anymore)
>
> --
> Teemu Keiski
> AspInsider, ASP.NET MVPhttp://blogs.aspadvice.com/jotekehttp://teemukeiski.net
>
> "jeeji" <jihad...@yahoo.com> wrote in message
>
> news:d3cb245c-c145-42a4-9820-(E-Mail Removed)...
>
> > Hi

>
> > I have a web application that has a main page in which the user inputs
> > some data in some input fields.
> > The page contains two buttons (Button1 and Button2) that do a
> > postback.
> > When Button1 is clicked I want to call a function called Validate1(),
> > and when Button2 is clicked I want to call Validate2(). Those
> > functions validate the data input in the input fields.
> > If data is not valid I want to mark the input field that caused the
> > datavalidation error.

>
> > What is the best practice way of doing this.
> > My problem is that when a button is clicked, page_load() is called
> > first, followed by the button click event handler.
> > I cannot put the calls to Validate1() or Validate2() in page_load,
> > because I cannot see which button was clicked.
> > But then, page_load typically draws the page to be rendered. But in
> > order to render the page, I have to know which input field caused the
> > validation error.

>
> > I would assume this is a typical scenario, which I cannot seem to
> > figure out.

>
> > Thanks in advance
> >Jeeji


 
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
custom data validation on cells with data validation values AKrobbins Microsoft Excel Worksheet Functions 2 21st Jun 2011 04:20 PM
Data Validation -> Validation list is larger than the cell width Barb Reinhardt Microsoft Excel Programming 1 4th Mar 2010 08:24 PM
Crazy Data Validation ... List Validation Not Working TW Bake Microsoft Excel Programming 1 29th Mar 2007 02:41 AM
data validation invalid in dynamic validation list ilia Microsoft Excel Programming 0 7th Nov 2006 12:54 PM
When pasting data into a column with data validation I lose validation check Brad Microsoft Excel Misc 5 17th Apr 2004 01:11 PM


Features
 

Advertising
 

Newsgroups
 


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