Dynamically set value of the elements attribute in ASP.NET

I have simple code on an aspx page

<object width="550" height="400"> <param name="movie" value='XXXX' /> <embed src='XXXX' width="350" height="370"></embed> </object> 

I want to be able to dynamically set the value of XXXX.

What is the best way to do this?

+4
source share
3 answers

You can add a property to your code, say "MyProperty", set the value at boot time, and then access this property directly in aspx ...

In codebehind ...

  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"; } } 

In Aspx ...

 ... <object width="550" height="400"> <param name="movie" value='<%= MyProperty %>' /> <embed src='<%= MyOtherProperty %>' width="350" height="370"></embed> </object> ... 
+7
source

Using jQuery, you can do it like this:

 $("param[name=movie]").attr("value", new value); 
0
source

Option 1

You can use server variable from Javascript function

Option 2

Add a placeholder or Literal and set the object with your attribute as a string

0
source

Source: https://habr.com/ru/post/1308209/


All Articles