Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2009
    Location
    US
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Passing a C# variable to included javascript file

    I few sites said to (in the js file) put the varible in <%= %> these tags but thats not doing any good. Is there some other part needed to this I'm missing. The javascript I'm using is in a file I included in my VS project.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    Quote Originally Posted by Sonar87 View Post
    The javascript I'm using is in a file I included in my VS project.
    That's the problem. The <%=...%> trick only works for JavaScript in the main ".aspx" file (or, at least, in some file *created* by ASP.NET). ASP.NET can't change the contents of static ".js" files.

    Without seeing the change you are trying to make, we could only guess at solutions.

    *POSSIBLY* you can do it by assigning to the JS variable in the .aspx files *before* the point of the <script src="xxx.js"> file, but that depends on the xxx.js file.

    Hard to answer you with no more than what you have posted so far.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Dec 2009
    Location
    US
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I'm working with an input field

    <input type='hidden' name='member_id' id='number' value='***' />

    changing the value like this

    document.getElementById("number").value=num;

    but I need to decide what the numbers going to be based on what the user clickes in the C# section. I'm working with Windows Presentation forundation so I'm using the buttons and everything from there. And the javascript/html stuff is included in the project and shown in a WPF frame object.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    Clear as mud to me. Maybe you need to ask this in some ASP.NET forum?

    But you could also simply bring the page up in your browser, click on the VIEW menu, click on the SOURCE menu item, and then copy/paste the relevant HTML to here.

    You can always add event handlers (e.g., onclick) to already-existing HTML by just executing some JS code when the page loads. I suspect that's what you need, but can't tell for sure from what you wrote because I don't "speak" that language. (Don't even know what WPF is, let alone "a WPF frame object".)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •