Whats the best way to programatically add a .swf to an asp.net page?

落花浮王杯 提交于 2019-12-11 16:13:39

问题


Is there a good way to add a .swf programatically to a panel on an asp.net page - ie: I know i could just insert the html tags:

ie:

<object type="application/x-shockwave-flash" data="yourflash.swf" width="" height="">
<param name="movie" value="yourflash.swf">
</object>

But is there an existing .net or free FLASH component already that you just set the properties on, or do i need to create a custom web control myself (not preferred) so i dont have to continously do this?

Thank you.


回答1:


FlashObject.cs:

namespace MyNamespace 
{ 
 using System.Web.UI;

 public class FlashObject : Control
 { public int Width  {get;set}
   public int Height {get;set}
   [UrlProperty] pubic string SourceUrl {get;set;}

   protected override Render(HtmlWriter writer)
    { writer.WriteLine( "<object type='application/x-shockwave-flash' "
                       +" data='{0}' width='{1}' height='{2}'>\r\n"
                       +"    <param name='movie' value='{0}'>\r\n</object>"
                       ,ResolveUrl(SourceUrl)
                       ,Width
                       ,Height);
    }
 }
}

Web.config:

  <system.web> 
     <controls>
       <add tagPrefix="my" namespace="MyNamespace" assembly="MyAssembly" />
     </controls>
  </system.web>

MyPage.aspx:

 <my:FlashObject SourceUrl='~/yourflash.swf' runat='server' />



回答2:


Do like above but instead of emmiting the object and embed code, include swfobject http://code.google.com/p/swfobject/ and emit some nice unintrusive javascript into your page to insert the swf!



来源:https://stackoverflow.com/questions/214568/whats-the-best-way-to-programatically-add-a-swf-to-an-asp-net-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!