CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2008
    Posts
    20

    Confirmation of delete for a drop down..

    Hello All,
    I have a problem in a project i am doing. Can any1 please help me in this.

    I have a drop down list as follows :

    Code:
    <asp:DropDownList  ID="PostActionDDL" runat="server" EnableViewState="false" OnSelectedIndexChanged="activeRegistrant_SelectedIndexChanged"
       AutoPostBack="true" >
                               <asp:ListItem Value="0">Select an Action</asp:ListItem>
                               <asp:ListItem Value="1">View</asp:ListItem>
                               <asp:ListItem Value="2">Delete</asp:ListItem>
           </asp:DropDownList>
    And i have the C# code as follows :
    Code:
     protected void activeRegistrant_SelectedIndexChanged(object sender, EventArgs e)
            {
               ///Some code..
                int selectedAction = Convert.ToInt32(dropList.SelectedValue);
    
                switch ((RegistrationActions)selectedAction)
                {
                    case RegistrationActions.View:
                        Response.Redirect("RegistrantDetails.aspx?id=" + registrationId.ToString());
                        break;
    
                    case RegistrationActions.Delete:
                        DeleteRegistration(registrationId);
                        //some code...
                        break;
                }
            }
    Now, everything here is fine and working. But now, if the user selects delete, the data is getting deleted correctly. But without any confirmation. So, if a user selects the delete in the drop down list, i want a pop up to ask " Are you sure you want to delete ?"
    And, if the user clicks view, i don't need any pop up.
    Can any1 please help me...

    Thanks
    Last edited by laptop545; June 22nd, 2010 at 10:38 AM.

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Confirmation of delete for a drop down..

    You need to assign a javascript for your and show a confirm and return that result from your script.
    If the user then clicks no/cancel - false is returned and the event is not send to the server.

    So I would guess something like this in your code behind would work ( - although it might need some tinkering, this is off the top of my head)
    Code:
    PostActionDDL.Attributes.Add("onChange", "return confirm('Are you sure?');");
    or add it in your markup

  3. #3
    Join Date
    Jun 2010
    Location
    Cairo, Egypt
    Posts
    17

    Re: Confirmation of delete for a drop down..

    not Agreed,
    this will cause the the confirm appear even if the user didn't chose the delete
    so you need OnChange as Alsvha said,
    but you need actually to call a JavaScript function
    and chick the value of the DropDownList if it was Delete Show the Confirm

  4. #4
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Confirmation of delete for a drop down..

    Quote Originally Posted by avrail View Post
    not Agreed,
    this will cause the the confirm appear even if the user didn't chose the delete
    so you need OnChange as Alsvha said,
    but you need actually to call a JavaScript function
    and chick the value of the DropDownList if it was Delete Show the Confirm
    Same systematic, and you can just add the drop down check into the onChange return statement.

  5. #5
    Join Date
    Jun 2010
    Location
    Cairo, Egypt
    Posts
    17

    Re: Confirmation of delete for a drop down..

    Quote Originally Posted by Alsvha View Post
    Same systematic, and you can just add the drop down check into the onChange return statement.
    great,
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    010011000111010101110110001000000100110101111001001000000101000001100011

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured