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. Access C# Variable in to java Script Function

Access C# Variable in to java Script Function

Scheduled Pinned Locked Moved C#
csharpjavajavascripttoolsquestion
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.
  • M Offline
    M Offline
    mharoonkhan
    wrote on last edited by
    #1

    Hi, i have a variable strpicture in c# code behind file and i want to pass this variable to a javascript function ShowPicture(take strpicture as parameter) how can i pass this variable to a javascript function if some one know please give me a hint.

    KnightGuy

    S V E 3 Replies Last reply
    0
    • M mharoonkhan

      Hi, i have a variable strpicture in c# code behind file and i want to pass this variable to a javascript function ShowPicture(take strpicture as parameter) how can i pass this variable to a javascript function if some one know please give me a hint.

      KnightGuy

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Hi, i'm not really sure what you want to achieve, but if you want to pass the content of the strpicture-variable to a javascript-function during the "onLoad" you could use hiddenfields. Just put strpicture into a hiddenfield of your asp-form and access the value of this field during the "onLoad". Should look like this (client-side):

      function onload() {
      value = document.getElementById("here goes the hiddenfield-name").value;
      ShowPicture(value);
      }

      ...

      <body onload='javascript:onload()'>...

      Hope this helps... Regards Sebastian

      1 Reply Last reply
      0
      • M mharoonkhan

        Hi, i have a variable strpicture in c# code behind file and i want to pass this variable to a javascript function ShowPicture(take strpicture as parameter) how can i pass this variable to a javascript function if some one know please give me a hint.

        KnightGuy

        V Offline
        V Offline
        vijaiganesh
        wrote on last edited by
        #3

        Or You can try this... by using RegisterStartupScript and pass the variable value from the code. public void Page_Load(Object sender, EventArgs e) { // Define the name and type of the client scripts on the page. String yourVariable = "yourVariable"; String csname1 = "PopupScript"; String csname2 = "ButtonClickScript"; Type cstype = this.GetType(); // Get a ClientScriptManager reference from the Page class. ClientScriptManager cs = Page.ClientScript; // Check to see if the startup script is already registered. if (!cs.IsStartupScriptRegistered(cstype, csname1)) { String cstext1 = "alert('Hello World');"; cs.RegisterStartupScript(cstype, csname1, cstext1, true); } // Check to see if the client script is already registered. if (!cs.IsClientScriptBlockRegistered(cstype, csname2)) { StringBuilder cstext2 = new StringBuilder(); cstext2.Append("script type=text/javascript; function DoClick("); cstext2.Append(yourVariable); cstext2.Append(") {"); cstext2.Append("Form1.Message.value='Text from client script.'} </"); cstext2.Append("script>"); cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false); } } I hope this helps... Cheers vj

        1 Reply Last reply
        0
        • M mharoonkhan

          Hi, i have a variable strpicture in c# code behind file and i want to pass this variable to a javascript function ShowPicture(take strpicture as parameter) how can i pass this variable to a javascript function if some one know please give me a hint.

          KnightGuy

          E Offline
          E Offline
          Ennis Ray Lynch Jr
          wrote on last edited by
          #4

          In Java the technology is/was called liveconnect. The best manner to do it now would be to write to the document stream new data or to have Javascript make continuous calls to the server. In your case I would just write the assignment to the file.

          Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
          Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
          Most of this sig is for Google, not ego.

          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