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. General Programming
  3. C#
  4. Executing Javascript based on a condition in codebehind

Executing Javascript based on a condition in codebehind

Scheduled Pinned Locked Moved C#
csharphelpjavascriptasp-netdatabase
4 Posts 2 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.
  • K Offline
    K Offline
    Krugger404
    wrote on last edited by
    #1

    Hi friends, I am currently working on an ASP.NET project using C# and i have one issue. Does anyone know how to trigger a javascript anywhere in C# code. eg : if(conditon) trigger javascript Can you please help me on this.Thank you Krugger The Truth is out there...

    G 1 Reply Last reply
    0
    • K Krugger404

      Hi friends, I am currently working on an ASP.NET project using C# and i have one issue. Does anyone know how to trigger a javascript anywhere in C# code. eg : if(conditon) trigger javascript Can you please help me on this.Thank you Krugger The Truth is out there...

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      You can add javascript using the Page.RegisterStartupScript method. Example: Page.RegisterStartupScript("ShowAnswer", "alert('42');"); --- b { font-weight: normal; }

      K 1 Reply Last reply
      0
      • G Guffa

        You can add javascript using the Page.RegisterStartupScript method. Example: Page.RegisterStartupScript("ShowAnswer", "alert('42');"); --- b { font-weight: normal; }

        K Offline
        K Offline
        Krugger404
        wrote on last edited by
        #3

        Thanks --- b { font-weight: normal; } I came across this but was unsure whether the script will run immediately. Can i do something like this (see below) to ensure that the Javascript ShowAnswer is fired only where MyBool is true? if(MyBool) Page.RegisterStartupScript("ShowAnswer", "alert('42');"); Krugger The truth is out there..

        G 1 Reply Last reply
        0
        • K Krugger404

          Thanks --- b { font-weight: normal; } I came across this but was unsure whether the script will run immediately. Can i do something like this (see below) to ensure that the Javascript ShowAnswer is fired only where MyBool is true? if(MyBool) Page.RegisterStartupScript("ShowAnswer", "alert('42');"); Krugger The truth is out there..

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          The code is placed just before the tag, so it will be run while the page is loading in the browser. If you don't execute the RegisterStartupScript call, the code is of course not added to the page. --- b { font-weight: normal; }

          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