View Full Version : Passing a C# variable to included javascript file

08-31-2010, 01:47 AM
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.

Old Pedant
08-31-2010, 03:33 AM
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.

08-31-2010, 04:02 AM
I'm working with an input field

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

changing the value like this


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.

Old Pedant
08-31-2010, 08:44 PM
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".)