Dev Sharma Dev Sharma - 1 year ago 84
Javascript Question

How to paas img src value dynamically from

i want to pass src value using and C# code.

Actually i want to use multiple HTML tags in which i want to set values from an C# code

<img src="[passed_value]" width="100" height="100" />


<video controls="controls" poster="[passed_value]" width="550" height="320">
<source src="../videos/2.mp4" type="video/mp4">

I want pass dynamic
value using webforms

Please help me regarding this...

Answer Source

The simplest solution is to write the variable values using the Response.Write shorthand syntax <%=variable%> like so:

C# WebForm Code Behind:

public string path; 
public string posterPath; 

protected void Page_Load(object sender, EventArgs e) { 
    path = "../videos/2.mp4"; 
    posterPath = "../images/user.jpg"; 


<img src="<%=path%>" width="100" height="100" />
<video controls="controls" poster="<%=posterPath%>" width="550" height="320">
   <source src="../videos/2.mp4" type="video/mp4"> 

Note: Answer posted for posterity from Dev Sharma's solution in question comments above.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download