Reputation: 3429
Im wondering if there is a way to easily change the src in the video tag in HTML5 from codebehind?
my solution now is to use different WebUserControl's and place them in a PlaceHolder when their button is clicked, but this fast leads to a lot of control's.
There has to be a better way.
maybe like placing a label, bind of some sort in the src
Upvotes: 0
Views: 11341
Reputation: 3429
solved it by placing this in the aspx page
<asp:PlaceHolder ID="VidModule" runat="server"></asp:PlaceHolder>
and this in the codebehind
//Video relevant int's
int width {get; set;}
int height { get; set; }
//Video relevant text's
string overskrift { get; set; }
string poster { get; set; }
string titleimg { get; set; }
string ogv { get; set; }
string mp4 { get; set; }
string webm { get; set; }
string reso { get; set; }
string res { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
}
//low 240i resolution player LowD
protected void low240i_Click(object sender, EventArgs e)
{
height = 480;
width = 640;
reso = "240i";
if (reso == "240i")
res = "240i/";
else if (reso == "240p")
res = "240p/";
else if (reso == "480p")
res = "480p/";
else if (reso == "720p")
res = "720p/";
int Data = Convert.ToInt32(Request.QueryString["id"]);
VideoDataContext db = new VideoDataContext();
var fetch = from list in db.VideoDBs
where
list.VidID == Data
select list;
foreach (var list in fetch)
{
overskrift = "\"" + list.Name + "\"";
poster = "\"" + list.IMGAddr + "\"";
titleimg = "\"" + list.IMGAddr + "\"";
if (list.mp4 == true)
mp4 = "\"" + "../Movies/Mov/" + res + list.VIDAddr + ".mp4" + "\"";
else
mp4 = null;
if (list.ogv == true)
ogv = "\"" + "../Movies/Mov/" + res + list.VIDAddr + ".ogv" + "\"";
else
ogv = null;
if (list.webm == true)
webm = "\"" + "../Movies/Mov/" + res + list.VIDAddr + ".webm" + "\"";
else
webm = null;
}
Panel1.Controls.Add(new LiteralControl("<div class=player ><br />"));
Panel1.Controls.Add(new LiteralControl("<h3>" + overskrift + " in " + reso + "</h3><br /><br />"));
Panel1.Controls.Add(new LiteralControl("<video controls=controls id=video width=" + "\"" + width + "\"" + " height=" + "\"" + height + "\"" + " poster=" + poster + " preload=auto >"));
Panel1.Controls.Add(new LiteralControl("<source src=" + mp4 + " type=\"video/mp4; codecs=avc1.42E01E, mp4a.40.2\" title=" + titleimg + " />"));
Panel1.Controls.Add(new LiteralControl("<source src=" + webm + " type=\"video/webm; codecs=vp8, vorbis\" title=" + titleimg + " />"));
Panel1.Controls.Add(new LiteralControl("<source src=" + ogv + " type=\"video/ogg; codecs=theora, vorbis\" title=" + titleimg + " />"));
Panel1.Controls.Add(new LiteralControl("Your browser does not support the video tag."));
Panel1.Controls.Add(new LiteralControl("</video></div>"));
}
Upvotes: 2
Reputation: 5806
Any tag can have attributes added to it in code-behind as long as you add a runat="server", so yes, there is.
in .aspx page:
<video id="videoTag" runat="server" />
code-behind:
videoTag.Attributes["src"] = "bob";
Alternatively you can write your own webcontrol. This involves more work and understanding of asp.net, but will be worth it if you're going to use this a lot.
And if you're using ASP.Net MVC, they've already released support for HTML5 in ASP.Net MVC 3 as I understand it.
Upvotes: 5