Confirmation box based on condition

Last post 07-09-2008 2:04 AM by Maulik Patel. 1 replies.

Sort Posts:

  • Confirmation box based on condition

    07-08-2008, 2:58 PM
    • Member
      5 point Member
    • muniappan
    • Member since 07-31-2007, 3:35 PM
    • New Jersey
    • Posts 53

    On click of the save button, I have to check whether the inventory item exists for the store. If exists then, I have to ask the user whether the user want to use the same item that was already deleted. I am trying to achieve this with the following code. I am having this code in the save button click. I am strugling with geting the result from the confirmation box[Yes/No]. It is not showing the confirmation box immediately after executing this code. so hidden1.value is empty. Can you please help me?

    string Script = "<script language='JavaScript'>document.getElementById('" + Hidden1.ID + "').value =confirm('This Item was previously deleted. Would you like to undelete the item ?'); GetPostBackEventReference(Hidden1, string.Empty);</script>";

    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "AskBringBackConfirm", Script);

    if (Hidden1.Value == "true")

    {

    }

    else

    {

    valCustomValidator.ErrorMessage =

    "Please enter an item number other than <b>[" + txtItemNumber.Text

    + "]</b>.</br>";

    valCustomValidator.IsValid = false;

    }

    Thanks,
    Athma
  • Re: Confirmation box based on condition

    07-09-2008, 2:04 AM
    Answer
    • Contributor
      2,342 point Contributor
    • Maulik Patel
    • Member since 12-21-2007, 1:48 AM
    • Ahmedabad
    • Posts 333

    If I have not misunderstood your code than you want to confirm user and if he press 'yes' than you want to proceed with some server code and if he press 'no' than you want to display message like "Please enter an item number other than ..."  right ?

    Than bellow is a sample code for you which will fire server event if user agree otherwise display message ...

     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" ValidateRequest="false" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
        <script>
        function CheckData()
        {
            if (confirm('This Item was previously deleted. Would you like to undelete the item ?'))
                return true;
            else
            {
                document.getElementById("error").innerHTML = "Please enter an item number other than <b>[" + document.getElementById("<%= txtItemNumber.ClientID %>").value + "]</b>.</br>";
                return false;
            }
        }
        </script>
    </head>
    <body >
    <form runat="server">
        <div id="error"></div>
        <asp:TextBox ID="txtItemNumber" runat="Server"></asp:TextBox>
        <asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="return CheckData();" />
    </form>
    </body>
    </html>
    

       

     

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
            'Do what you want to do when user press 'yes'
    
    End Sub
      
    Maulik Patel
    MCTS, Software Engineer

    Don't forget to click "Mark as Answer" on the post that helped you. This will give you point and help readers to know which post solved your issue and make their search easy.
Page 1 of 1 (2 items)