Reputation: 167
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.
Upvotes: 1
Views: 446
Reputation: 8938
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.
Upvotes: 1
Reputation: 746
You can set the value in the code behind and use it in the markup like this:
<%= MyUrlVariable %>
Upvotes: 1
Reputation: 32694
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.
Upvotes: 1
Reputation: 5222
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
});
Upvotes: 3