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. Button click event asp.net 2.0

Button click event asp.net 2.0

Scheduled Pinned Locked Moved ASP.NET
helpcsharpjavascriptasp-net
6 Posts 3 Posters 1 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
    netJP12L
    wrote on last edited by
    #1

    Hi guys, I am counting Items on button click if total items are 5 then i want to display a popup or alert message through javascript. Currently i am calling in my button click event like this: button.OnClientClick="javascript:alert('5 Items');"; The problem is I had to click twice to invoke this message. lets say the counter is 5, I clicked on messages appears, I clicked again then I do see this message. Can someone help me in it. Thanks

    C C 2 Replies Last reply
    0
    • N netJP12L

      Hi guys, I am counting Items on button click if total items are 5 then i want to display a popup or alert message through javascript. Currently i am calling in my button click event like this: button.OnClientClick="javascript:alert('5 Items');"; The problem is I had to click twice to invoke this message. lets say the counter is 5, I clicked on messages appears, I clicked again then I do see this message. Can someone help me in it. Thanks

      C Offline
      C Offline
      CodyGen
      wrote on last edited by
      #2

      you can try putting this under Button_Click event Response.Write("javascript:alert('5 items');");

      N 1 Reply Last reply
      0
      • C CodyGen

        you can try putting this under Button_Click event Response.Write("javascript:alert('5 items');");

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

        Thanks for answering. Acutally i have created those button inside an ajax updatepanel. That's y i couldn't use response.write method becuase it throws exception. Is there anyother way. Thanks

        1 Reply Last reply
        0
        • N netJP12L

          Hi guys, I am counting Items on button click if total items are 5 then i want to display a popup or alert message through javascript. Currently i am calling in my button click event like this: button.OnClientClick="javascript:alert('5 Items');"; The problem is I had to click twice to invoke this message. lets say the counter is 5, I clicked on messages appears, I clicked again then I do see this message. Can someone help me in it. Thanks

          C Offline
          C Offline
          ChrisKo 0
          wrote on last edited by
          #4

          Here's what I would do (note: ItemCount is a property I have wired to a Session value, you could easily make it a database driven value).

          protected void Button1_Click(object sender, EventArgs e)
          {
          ItemCount += 1;

          if (ItemCount == 4)
          	Button1.Attributes.Add("onClick", "alert('5 Items');");
          else if (ItemCount == 5)
          	Button1.Attributes.Remove("onClick");
          

          }

          N 1 Reply Last reply
          0
          • C ChrisKo 0

            Here's what I would do (note: ItemCount is a property I have wired to a Session value, you could easily make it a database driven value).

            protected void Button1_Click(object sender, EventArgs e)
            {
            ItemCount += 1;

            if (ItemCount == 4)
            	Button1.Attributes.Add("onClick", "alert('5 Items');");
            else if (ItemCount == 5)
            	Button1.Attributes.Remove("onClick");
            

            }

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

            I tried but doesn't work. I only want to display the javascript alert box when there are 5 or more itmes . As i mentioned before button1.attributes.add("onclick","javascript:alert('5 Items');"); display alert message when i click on twice. Please help me and am stuck dont' know how to solve this issuse.

            C 1 Reply Last reply
            0
            • N netJP12L

              I tried but doesn't work. I only want to display the javascript alert box when there are 5 or more itmes . As i mentioned before button1.attributes.add("onclick","javascript:alert('5 Items');"); display alert message when i click on twice. Please help me and am stuck dont' know how to solve this issuse.

              C Offline
              C Offline
              ChrisKo 0
              wrote on last edited by
              #6

              The code I provided above will add the onClick event after you've clicked the button 4 times. So that means on the 5th click, the onClick event will cause the alert() to show. Then I remove the onClick event because you only wanted to show the alert() on the 5th time. I've tested this code locally and it works fine. Can you show us more of your code so we can see where the problem really is?

              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