Different validation of data

Discussion in 'ASP .Net' started by jeeji, Aug 5, 2008.

  1. jeeji

    jeeji Guest

    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
     
    jeeji, Aug 5, 2008
    #1
    1. Advertising

  2. jeeji

    Teemu Keiski Guest

    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" <> wrote in message
    news:...
    > 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
     
    Teemu Keiski, Aug 6, 2008
    #2
    1. Advertising

  3. jeeji

    jeeji Guest

    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" <> 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" <> wrote in message
    >
    > news:...
    >
    > > 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
     
    jeeji, Aug 13, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Mackay
    Replies:
    0
    Views:
    2,695
    Colin Mackay
    Jun 25, 2003
  2. Libs
    Replies:
    0
    Views:
    1,504
  3. AD
    Replies:
    1
    Views:
    1,051
    Francis Shanahan
    Aug 23, 2003
  4. Fabrizio Pollastri
    Replies:
    2
    Views:
    346
  5. Christopher Brewster
    Replies:
    5
    Views:
    347
    John Machin
    Nov 14, 2008
Loading...

Share This Page