javascript yes no button

Discussion in 'ASP .Net' started by mark, Mar 2, 2004.

  1. mark

    mark Guest

    i have a public boolean variable called exit - it should run like this

    if variable = true then (javascript msgbox with you havent saved would you
    like to yes/no)
    if no then Response.Redirect("index.aspx")

    cheers

    mark
     
    mark, Mar 2, 2004
    #1
    1. Advertisements

  2. mark

    Simon Gorski Guest

    Hello Mark,
    if variable = true then
    Page.RegisterClientScriptBlock("jsPopUp","<script
    language='javascript'>answer = confirm('Save?') <script>");
    end if

    mfg simon g.
     
    Simon Gorski, Mar 2, 2004
    #2
    1. Advertisements

  3. mark

    mark Guest

    thanks but that doesnt appear to do anything!

    ive the line :-

    RegisterStartupScript("startupScript", "<script
    language=JavaScript>confirm('you have unsaved data - click yes to
    save');</script>")
    just need to know how to process the yes no clicks
    btw im using codebehind and aspx

    thanks

    mark
     
    mark, Mar 2, 2004
    #3
  4. mark

    Simon Gorski Guest

    Hello Mark,
    1. make a input type-hidden value (id=hdnSave)
    2. make a js- function Save()
    {
    myValue = confirm('you have unsaved data -click yes to save')
    if (myValue)
    {
    window.document.getElementById('hdnSave').value = 1;
    }
    else
    {
    window.document.getElementById('hdnSave').value = 1;
    }

    }
    3. Add the Script to the Button
    btnNext.Attributes.Add("onClick","Save()");
    4. Ask CodeBehind
    if (hdnSave.Value=="1")
    //Save
    else
    //do what you like

    mfg simon g.
     
    Simon Gorski, Mar 2, 2004
    #4
  5. mark

    mark Guest

    thanks ill give that a try

    mark

     
    mark, Mar 2, 2004
    #5
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.