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. Executing JavaScript on asp:button_click event

Executing JavaScript on asp:button_click event

Scheduled Pinned Locked Moved ASP.NET
javascripttools
4 Posts 4 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.
  • G Offline
    G Offline
    gauthee
    wrote on last edited by
    #1

    Hi, I have a button named btn1, now under the btn1_click event i wrote the following: if(condition) { } else { this.RegisterClientScriptBlock("",DisplayAlert()); } ------------- public string DisplayAlert() { string script=""; script += ; script += "alert('Text');"; script += " } Now the alert is being displayed but the entire page is being blank when displaying the alert box. The requirement is that original page should be at the background while displaying the alert message. Thanks

    Gautham

    _ H M 3 Replies Last reply
    0
    • G gauthee

      Hi, I have a button named btn1, now under the btn1_click event i wrote the following: if(condition) { } else { this.RegisterClientScriptBlock("",DisplayAlert()); } ------------- public string DisplayAlert() { string script=""; script += ; script += "alert('Text');"; script += " } Now the alert is being displayed but the entire page is being blank when displaying the alert box. The requirement is that original page should be at the background while displaying the alert message. Thanks

      Gautham

      _ Offline
      _ Offline
      _AK_
      wrote on last edited by
      #2

      Actually the javascript has to get registered on page load. In your case it is happening after you click the button.

      Best Regards, Apurva Kaushal

      1 Reply Last reply
      0
      • G gauthee

        Hi, I have a button named btn1, now under the btn1_click event i wrote the following: if(condition) { } else { this.RegisterClientScriptBlock("",DisplayAlert()); } ------------- public string DisplayAlert() { string script=""; script += ; script += "alert('Text');"; script += " } Now the alert is being displayed but the entire page is being blank when displaying the alert box. The requirement is that original page should be at the background while displaying the alert message. Thanks

        Gautham

        H Offline
        H Offline
        hakonvik
        wrote on last edited by
        #3

        You can registrer the buttons onclick event by using button.Attributes.Add("onclick","DisplayAlert();"); If you now add the javascript function to the page's html and remove the original click event in code it should all work fine. HV

        1 Reply Last reply
        0
        • G gauthee

          Hi, I have a button named btn1, now under the btn1_click event i wrote the following: if(condition) { } else { this.RegisterClientScriptBlock("",DisplayAlert()); } ------------- public string DisplayAlert() { string script=""; script += ; script += "alert('Text');"; script += " } Now the alert is being displayed but the entire page is being blank when displaying the alert box. The requirement is that original page should be at the background while displaying the alert message. Thanks

          Gautham

          M Offline
          M Offline
          MihirV
          wrote on last edited by
          #4

          Try it using RegisterStartupScript(Type, string, string), it will work as per ur expectation. :)


          Confidence comes not from always being right, but from not fearing to be wrong. Mihir..

          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