在ASP.NET中动态设置元素属性的值

Ant*_*ony 4 html asp.net

我在aspx页面中有一些简单的代码

<object width="550" height="400">
    <param name="movie" value='XXXX' />
    <embed src='XXXX' width="350" height="370"></embed>
</object>
Run Code Online (Sandbox Code Playgroud)

我希望能够动态设置XXXX的值.

做这个的最好方式是什么 ?

mar*_*rkt 7

你可以在你的代码隐藏中添加一个属性,比如'MyProperty',在加载期间设置值,然后在你的aspx中访问该属性...

在代码隐藏中......

 public partial class _Default : System.Web.UI.Page
 {
    protected string MyProperty { get; set; }
    protected string MyOtherProperty { get;set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        MyProperty = "SomeValue";
        MyOtherProperty = "SomeOtherValue";
    }
 }
Run Code Online (Sandbox Code Playgroud)

在Aspx ......

...
<object width="550" height="400">
<param name="movie" value='<%= MyProperty %>' />
<embed src='<%= MyOtherProperty %>' width="350" height="370"></embed>
</object>
...
Run Code Online (Sandbox Code Playgroud)