Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. [Solved]Confirmation Box Problem [modified]

[Solved]Confirmation Box Problem [modified]

Scheduled Pinned Locked Moved ASP.NET
helpcsharpjavascriptasp-netquestion
15 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nagendrathecoder
    wrote on last edited by
    #1

    Hello All, In my ASP.Net application, i am showing a confirmation box using javascript whenever user intends to delete something. I have written this code in aspx file

    function confirmation()
    {
    if(confirm("Are you sure?")==true)
    return true;
    else
    return false;
    }

    Then on Page_Load of my codebehind, i am using this:

    btnDelete.Attributes.Add("onclick", "return confirmation();")

    It is working fine, if user click ok record is deleting and vice versa. But when i am trying to write same thing for my GridView delete link its not working, i am writting this:

    GridView1.Attributes.Add("OnRowDeleting", "return confirmation();");

    Can anybody help me? why its not working for GridView_RowDeleting method? Thanks, Nagendra.

    modified on Thursday, September 24, 2009 7:06 AM

    C S N 3 Replies Last reply
    0
    • N nagendrathecoder

      Hello All, In my ASP.Net application, i am showing a confirmation box using javascript whenever user intends to delete something. I have written this code in aspx file

      function confirmation()
      {
      if(confirm("Are you sure?")==true)
      return true;
      else
      return false;
      }

      Then on Page_Load of my codebehind, i am using this:

      btnDelete.Attributes.Add("onclick", "return confirmation();")

      It is working fine, if user click ok record is deleting and vice versa. But when i am trying to write same thing for my GridView delete link its not working, i am writting this:

      GridView1.Attributes.Add("OnRowDeleting", "return confirmation();");

      Can anybody help me? why its not working for GridView_RowDeleting method? Thanks, Nagendra.

      modified on Thursday, September 24, 2009 7:06 AM

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      nagendrathecoder wrote:

      function confirmation() { if(confirm("Are you sure?")==true) return true; else return false; }

      This is messy as hell. Why not just return (confirm("Are you sure?")) ? Why not tell them what they are to be sure if, in case they don't realise what they pushed ?

      nagendrathecoder wrote:

      GridView1.Attributes.Add("OnRowDeleting", "return confirmation();");

      I'd guess that it's because you're trying to hook up to a code behind event, not an actual client side event. You could start by reading on the difference between the client and server.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      N 1 Reply Last reply
      0
      • C Christian Graus

        nagendrathecoder wrote:

        function confirmation() { if(confirm("Are you sure?")==true) return true; else return false; }

        This is messy as hell. Why not just return (confirm("Are you sure?")) ? Why not tell them what they are to be sure if, in case they don't realise what they pushed ?

        nagendrathecoder wrote:

        GridView1.Attributes.Add("OnRowDeleting", "return confirmation();");

        I'd guess that it's because you're trying to hook up to a code behind event, not an actual client side event. You could start by reading on the difference between the client and server.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        N Offline
        N Offline
        nagendrathecoder
        wrote on last edited by
        #3

        Thanks, i implemented what u mentioned(used just confirm & displaying proper msg). :) I also understand that RowDeleting is server side event and onclick is client side. But i want this functionality to work for GridView too, what can i do?

        1 Reply Last reply
        0
        • N nagendrathecoder

          Hello All, In my ASP.Net application, i am showing a confirmation box using javascript whenever user intends to delete something. I have written this code in aspx file

          function confirmation()
          {
          if(confirm("Are you sure?")==true)
          return true;
          else
          return false;
          }

          Then on Page_Load of my codebehind, i am using this:

          btnDelete.Attributes.Add("onclick", "return confirmation();")

          It is working fine, if user click ok record is deleting and vice versa. But when i am trying to write same thing for my GridView delete link its not working, i am writting this:

          GridView1.Attributes.Add("OnRowDeleting", "return confirmation();");

          Can anybody help me? why its not working for GridView_RowDeleting method? Thanks, Nagendra.

          modified on Thursday, September 24, 2009 7:06 AM

          S Offline
          S Offline
          sashidhar
          wrote on last edited by
          #4

          try to add itemtemplate in gridview and do it

          <ItemTemplate>

                              <asp:LinkButton ID="Delete" CommandName="Delete" 
                              OnClientClick="return confirm('Are you sure you wish to delete this item?')" 
                              CausesValidation="false" 
                               runat="server" Text="Delete" ></asp:LinkButton>
                          </ItemTemplate>
          

          If It Helps Click It as Answer

          N 2 Replies Last reply
          0
          • S sashidhar

            try to add itemtemplate in gridview and do it

            <ItemTemplate>

                                <asp:LinkButton ID="Delete" CommandName="Delete" 
                                OnClientClick="return confirm('Are you sure you wish to delete this item?')" 
                                CausesValidation="false" 
                                 runat="server" Text="Delete" ></asp:LinkButton>
                            </ItemTemplate>
            

            If It Helps Click It as Answer

            N Offline
            N Offline
            nagendrathecoder
            wrote on last edited by
            #5

            i am using ItemTemplate rite now :) Let me try with that OnClientClick.

            S 1 Reply Last reply
            0
            • S sashidhar

              try to add itemtemplate in gridview and do it

              <ItemTemplate>

                                  <asp:LinkButton ID="Delete" CommandName="Delete" 
                                  OnClientClick="return confirm('Are you sure you wish to delete this item?')" 
                                  CausesValidation="false" 
                                   runat="server" Text="Delete" ></asp:LinkButton>
                              </ItemTemplate>
              

              If It Helps Click It as Answer

              N Offline
              N Offline
              nagendrathecoder
              wrote on last edited by
              #6

              hey thanks man, its working alright. :-D

              S A 2 Replies Last reply
              0
              • N nagendrathecoder

                i am using ItemTemplate rite now :) Let me try with that OnClientClick.

                S Offline
                S Offline
                sashidhar
                wrote on last edited by
                #7

                :thumbsup:

                If It Helps Click It as Answer

                1 Reply Last reply
                0
                • N nagendrathecoder

                  hey thanks man, its working alright. :-D

                  S Offline
                  S Offline
                  sashidhar
                  wrote on last edited by
                  #8

                  No Problem Any Time..!:thumbsup::cool:

                  If It Helps Click It as Answer

                  1 Reply Last reply
                  0
                  • N nagendrathecoder

                    hey thanks man, its working alright. :-D

                    A Offline
                    A Offline
                    Abhijit Jana
                    wrote on last edited by
                    #9

                    nagendrathecoder wrote:

                    , its working alright.

                    Then you should vote / Rate his answer which helps you :)

                    Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                    N 1 Reply Last reply
                    0
                    • A Abhijit Jana

                      nagendrathecoder wrote:

                      , its working alright.

                      Then you should vote / Rate his answer which helps you :)

                      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                      N Offline
                      N Offline
                      nagendrathecoder
                      wrote on last edited by
                      #10

                      I did it. ;)

                      A 1 Reply Last reply
                      0
                      • N nagendrathecoder

                        Hello All, In my ASP.Net application, i am showing a confirmation box using javascript whenever user intends to delete something. I have written this code in aspx file

                        function confirmation()
                        {
                        if(confirm("Are you sure?")==true)
                        return true;
                        else
                        return false;
                        }

                        Then on Page_Load of my codebehind, i am using this:

                        btnDelete.Attributes.Add("onclick", "return confirmation();")

                        It is working fine, if user click ok record is deleting and vice versa. But when i am trying to write same thing for my GridView delete link its not working, i am writting this:

                        GridView1.Attributes.Add("OnRowDeleting", "return confirmation();");

                        Can anybody help me? why its not working for GridView_RowDeleting method? Thanks, Nagendra.

                        modified on Thursday, September 24, 2009 7:06 AM

                        N Offline
                        N Offline
                        Nisha Agrawal
                        wrote on last edited by
                        #11

                        The same thing will work here. actually you are not adding it at correct place. First of all, u are adding the attribute to Grid view. In fact when u wanna delete any item then i m sure u have placed some control in each row on clicking of that , that particular item will be deleted. So if it is a LinkButton/Button in ItemTemplate then you can add the attribute to it onRowDataBound Event or RowCreated Event or OnClientClick Property itself.

                        OR

                        ImageButton btn = (ImageButton)(e.Row.FindControl("imgbtnDelete"));
                        btn.Attributes.Add("OnClientClick","funcationToBecalled();")

                        N 1 Reply Last reply
                        0
                        • N Nisha Agrawal

                          The same thing will work here. actually you are not adding it at correct place. First of all, u are adding the attribute to Grid view. In fact when u wanna delete any item then i m sure u have placed some control in each row on clicking of that , that particular item will be deleted. So if it is a LinkButton/Button in ItemTemplate then you can add the attribute to it onRowDataBound Event or RowCreated Event or OnClientClick Property itself.

                          OR

                          ImageButton btn = (ImageButton)(e.Row.FindControl("imgbtnDelete"));
                          btn.Attributes.Add("OnClientClick","funcationToBecalled();")

                          N Offline
                          N Offline
                          nagendrathecoder
                          wrote on last edited by
                          #12

                          Nisha Agrawal wrote:

                          ImageButton btn = (ImageButton)(e.Row.FindControl("imgbtnDelete")); btn.Attributes.Add("OnClientClick","funcationToBecalled();")

                          Hmmm, this is also working. Thanks to u too. :)

                          S 1 Reply Last reply
                          0
                          • N nagendrathecoder

                            Nisha Agrawal wrote:

                            ImageButton btn = (ImageButton)(e.Row.FindControl("imgbtnDelete")); btn.Attributes.Add("OnClientClick","funcationToBecalled();")

                            Hmmm, this is also working. Thanks to u too. :)

                            S Offline
                            S Offline
                            sashidhar
                            wrote on last edited by
                            #13

                            Then Use Only One ..! Not Both...! :laugh:

                            If It Helps Click It as Answer

                            N 1 Reply Last reply
                            0
                            • S sashidhar

                              Then Use Only One ..! Not Both...! :laugh:

                              If It Helps Click It as Answer

                              N Offline
                              N Offline
                              nagendrathecoder
                              wrote on last edited by
                              #14

                              ofcourse :laugh: ;P

                              1 Reply Last reply
                              0
                              • N nagendrathecoder

                                I did it. ;)

                                A Offline
                                A Offline
                                Abhijit Jana
                                wrote on last edited by
                                #15

                                Thanks !

                                Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups