C#点击图片打开YouTube视频

时间:2014-09-24 15:43:25

标签: c# asp.net

我有一个ImageButton:

    <asp:ImageButton  runat="server" width="640" height="360" ID="imgButton" OnClick="ImageClick" />

当我点击它时,我做了一些验证。如果一切都结果正常,我喜欢做的是用a替换该图像 Youtube视频如此:

   <iframe width="560" height="315" src="//www.youtube.com/embed/ZtcptQruWDg" frameborder="0" allowfullscreen></iframe>

想知道最好的方法是什么。

2 个答案:

答案 0 :(得分:1)

使用纯javascript / jQuery解决方案:

从ImageButton

呈现的Html
<input type="image" src="http://dummy-images.com/abstract/dummy-107x160-DesiccationCracks.jpg" title="Click to disable this rule" id="imgButton" name="imgButton">

<强>的JavaScript

$(function(){

    $('#imgButton').click(function() {
        $(this).replaceWith(' <iframe width="560" height="315" src="//www.youtube.com/embed/ZtcptQruWDg" frameborder="0" allowfullscreen></iframe>');
    })

});

jsFiddle

答案 1 :(得分:0)

从您拥有的代码中,您似乎对服务器端代码感兴趣,我建议将该按钮放入ASP面板并按下按钮单击使用以下代码,假设面板ID为&#34; P&#34 ;

 p.Controls.Add(new LiteralControl("<iframe width='560'  height='315' src='//www.youtube.com/embed/ZtcptQruWDg' frameborder='0' allowfullscreen></iframe>"));
相关问题