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
  1. Home
  2. Web Development
  3. ASP.NET
  4. javascript function call from user control's command button

javascript function call from user control's command button

Scheduled Pinned Locked Moved ASP.NET
javascript
5 Posts 3 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
    Neeraj Arora
    wrote on last edited by
    #1

    Hi all, I have a user control having a command button. On click of button, I've bound a javascript function which should show a div control. But, when I click on button, it postback the page. cmdPostComment.Attributes.Add("onClick", "return showDiv();") function showDiv() { document.getElementById("divPostComment_Tab1").style.display = "block"; return false; } I've noticed one thing, When page renders, command buttons name got changed to "control1$cmdPostComment". Thanks in advance.

    C N 2 Replies Last reply
    0
    • N Neeraj Arora

      Hi all, I have a user control having a command button. On click of button, I've bound a javascript function which should show a div control. But, when I click on button, it postback the page. cmdPostComment.Attributes.Add("onClick", "return showDiv();") function showDiv() { document.getElementById("divPostComment_Tab1").style.display = "block"; return false; } I've noticed one thing, When page renders, command buttons name got changed to "control1$cmdPostComment". Thanks in advance.

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

      Add it as OnClientClick in your aspx page. That should work.

      Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

      N 1 Reply Last reply
      0
      • C Christian Graus

        Add it as OnClientClick in your aspx page. That should work.

        Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

        N Offline
        N Offline
        Neeraj Arora
        wrote on last edited by
        #3

        No luck

        C 1 Reply Last reply
        0
        • N Neeraj Arora

          No luck

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

          Do you have auto postback turned on ? I do this all the time and it works fine, set the OnClientClick, return false from it, and the Onclick will not run.

          Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.

          1 Reply Last reply
          0
          • N Neeraj Arora

            Hi all, I have a user control having a command button. On click of button, I've bound a javascript function which should show a div control. But, when I click on button, it postback the page. cmdPostComment.Attributes.Add("onClick", "return showDiv();") function showDiv() { document.getElementById("divPostComment_Tab1").style.display = "block"; return false; } I've noticed one thing, When page renders, command buttons name got changed to "control1$cmdPostComment". Thanks in advance.

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

            Neeraj Arora wrote:

            document.getElementById("divPostComment_Tab1").style.display = "block";

            Check the ID of "divPostComment_Tab1" after rendering of the page and use that ID instead of "divPostComment_Tab1".

            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