1

I have the following JavaScript and i need to set the "file" to some string from the c# code.

how can i do that ?

<script type="text/javascript">

    jwplayer("myElement").setup({
        file: "rtmp://localhost/someFolder/ + VideoFile/,
        height: 240,
        image: "/assets/myVideo.jpg",
        rtmp: {
            bufferlength: 0.1
        },
        width: 280
    });

</script>

c#

String VideoFile = "Some video file link"; // example Video01.flv

So, the result will be:

file: "rtmp://localhost/someFolder/Video01.flv/,

Thanks for the helpers.

2

4 Answers 4

3

Create property and set the value at the page load time and access the same in aspx file

Code behind

public string VideoFile { get; set; }

public void Page_Load(object sender, EventArgs e)
{
    VideoFile = "Video01.flv";
}

Aspx

jwplayer("myElement").setup({
    file: "rtmp://localhost/someFolder/<%= VideoFile %>",
    height: 240,
    image: "/assets/myVideo.jpg",
    rtmp: {
        bufferlength: 0.1
    },
    width: 280
});
Sign up to request clarification or add additional context in comments.

Comments

1

Create a public property on your code behind. Notice it has to be public in order to be seen by the markup page. Let's initialize it in page load.

Code Behind

public string VideoFile {get; set;}

protected void Page_Load(object sender, EventArgs e)
{
    VideoFile="myfile.mp4";
}

Then change your script so that you embed the property inline.

Markup

<script type="text/javascript">
                    jwplayer("myElement").setup({
                        file: "rtmp://localhost/someFolder/<%= VideoFile %>",
                        height: 240,
                        image: "/assets/myVideo.jpg",
                        rtmp: {
                            bufferlength: 0.1
                        },
                        width: 280
                    });
                </script>

For more info about inline server tags, see this blog post.

Comments

1

You can set the value in the code behind and use it in the markup like this:

<%= MyUrlVariable %>

1 Comment

Why the extra % sign?
1

You can use the .NET string property's value in the markup as follows:

<script type="text/javascript">

    jwplayer("myElement").setup({
        file: "rtmp://localhost/someFolder/<%= this.VideoFile %>",
        height: 240,
        image: "/assets/myVideo.jpg",
        rtmp: {
            bufferlength: 0.1
        },
        width: 280
    });

</script>

A related SO question speaks to using .NET class properties in markup more generally.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.