page validation help

Discussion in 'ASP .Net' started by =?Utf-8?B?QUNhdW50ZXI=?=, Dec 22, 2004.

  1. Hi all,
    I needed to have a validation to prevent someone from leaving the page if
    they added anything to it. I have about 10 imagebuttons at the top of the
    page for menu selections, and i wanted to have a warningmessage pop up if
    they select any of those without clicking the save button first.
    I put :
    If session("save") = "no" then
    ImageButton1.Attributes.Add("onclick", "return confirm('Are you sure you
    want to exit without saving?');")
    end if...
    in the page load event , and it works, but it will always show this message
    now.. even if they selected the save button.

    I use session variables to determine if it's been clicked, and in the page
    load i check to see if the session var. is what its suppose to be, but it
    will still always show it nomatter what...
    What should i do???
    --
    =?Utf-8?B?QUNhdW50ZXI=?=, Dec 22, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?QUNhdW50ZXI=?=

    chanmmn Guest

    Try to check for you logic and Ispostback event. Example:

    Sub Page_Load
    If Not IsPostBack
    ' Validate initially to force the asterisks
    ' to appear before the first roundtrip.
    Validate()
    End If
    End Sub


    chanmm

    "ACaunter" <> wrote in message
    news:...
    > Hi all,
    > I needed to have a validation to prevent someone from leaving the page if
    > they added anything to it. I have about 10 imagebuttons at the top of the
    > page for menu selections, and i wanted to have a warningmessage pop up if
    > they select any of those without clicking the save button first.
    > I put :
    > If session("save") = "no" then
    > ImageButton1.Attributes.Add("onclick", "return confirm('Are you sure you
    > want to exit without saving?');")
    > end if...
    > in the page load event , and it works, but it will always show this
    > message
    > now.. even if they selected the save button.
    >
    > I use session variables to determine if it's been clicked, and in the page
    > load i check to see if the session var. is what its suppose to be, but it
    > will still always show it nomatter what...
    > What should i do???
    > --
    >
    chanmmn, Dec 22, 2004
    #2
    1. Advertising

  3. Thanks for the quick reply,
    I'm not sure if i could use the postback option, because there are other
    buttons and dropdowns which are used on the page, so many postback will occur
    before the user enters info and clicks save...
    its for a schedule page, so i have if there is a textchange in any of the
    textboxes, then it should pop up with a message if the user hasn't clicked
    save..

    "chanmmn" wrote:

    > Try to check for you logic and Ispostback event. Example:
    >
    > Sub Page_Load
    > If Not IsPostBack
    > ' Validate initially to force the asterisks
    > ' to appear before the first roundtrip.
    > Validate()
    > End If
    > End Sub
    >
    >
    > chanmm
    >
    > "ACaunter" <> wrote in message
    > news:...
    > > Hi all,
    > > I needed to have a validation to prevent someone from leaving the page if
    > > they added anything to it. I have about 10 imagebuttons at the top of the
    > > page for menu selections, and i wanted to have a warningmessage pop up if
    > > they select any of those without clicking the save button first.
    > > I put :
    > > If session("save") = "no" then
    > > ImageButton1.Attributes.Add("onclick", "return confirm('Are you sure you
    > > want to exit without saving?');")
    > > end if...
    > > in the page load event , and it works, but it will always show this
    > > message
    > > now.. even if they selected the save button.
    > >
    > > I use session variables to determine if it's been clicked, and in the page
    > > load i check to see if the session var. is what its suppose to be, but it
    > > will still always show it nomatter what...
    > > What should i do???
    > > --
    > >

    >
    >
    >
    =?Utf-8?B?QUNhdW50ZXI=?=, Dec 22, 2004
    #3
  4. I've played around with the session variables, and now i sort of get it to
    work...
    if i make changes to the schedule page, and don't save anything, then i can
    leave and go to another page, do whatever else, and the next time i go back
    to the schedule page it will give me the "Are you sure" message for the
    previous time.. and the next time will be this time's messages... so it's
    pretty much always back one..
    Just sucks the info is already gone when you leave the page, so the late
    message is useless...

    "chanmmn" wrote:

    > Try to check for you logic and Ispostback event. Example:
    >
    > Sub Page_Load
    > If Not IsPostBack
    > ' Validate initially to force the asterisks
    > ' to appear before the first roundtrip.
    > Validate()
    > End If
    > End Sub
    >
    >
    > chanmm
    >
    > "ACaunter" <> wrote in message
    > news:...
    > > Hi all,
    > > I needed to have a validation to prevent someone from leaving the page if
    > > they added anything to it. I have about 10 imagebuttons at the top of the
    > > page for menu selections, and i wanted to have a warningmessage pop up if
    > > they select any of those without clicking the save button first.
    > > I put :
    > > If session("save") = "no" then
    > > ImageButton1.Attributes.Add("onclick", "return confirm('Are you sure you
    > > want to exit without saving?');")
    > > end if...
    > > in the page load event , and it works, but it will always show this
    > > message
    > > now.. even if they selected the save button.
    > >
    > > I use session variables to determine if it's been clicked, and in the page
    > > load i check to see if the session var. is what its suppose to be, but it
    > > will still always show it nomatter what...
    > > What should i do???
    > > --
    > >

    >
    >
    >
    =?Utf-8?B?QUNhdW50ZXI=?=, Dec 22, 2004
    #4
    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,678
    Colin Mackay
    Jun 25, 2003
  2. Libs
    Replies:
    0
    Views:
    1,483
  3. Colin Basterfield

    Web form validation vs object validation

    Colin Basterfield, Nov 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    421
    Tommy
    Nov 29, 2003
  4. =?Utf-8?B?ZGh1cndpdHo=?=
    Replies:
    1
    Views:
    442
    Teemu Keiski
    Apr 10, 2004
  5. Sudip
    Replies:
    0
    Views:
    186
    Sudip
    Jul 1, 2005
Loading...

Share This Page