tags:

views:

83

answers:

4

I am trying to put a path kept in a string variable (named "ruta") into the parameters of the swfobject.embedSWFfuntion but I don't know how to incorporate a c# code into javascript code. Can someone help me please?? thanks!!!!!

<%TarjetaPL tarjetaPl = null;
string ruta = null;
if (Session[Constantes.TarjetaSeleccionada] != null)
{
tarjetaPl = new TarjetaPL((Tarjeta)Session[Constantes.TarjetaSeleccionada]);
ruta = "../../content/images/" + tarjetaPl.TipoDeTarjeta.Banner;
}%>
<script type="text/javascript">
         swfobject.embedSWF((HERE COMES THE PATH KEPT IN THE VARIABLE "ruta"), "flashBanner", "300", "120", "9.0.0");
</script>

The problem is that the code doesn't even recognize the " <% %> " tag to incorporate c# on it!

+3  A: 

You want something like:

<script type="text/javascript">
         swfobject.embedSWF(<%=ruta%>, "flashBanner", "300", "120", "9.0.0");
</script>

Sorry it's been a while since I did web-based C# stuff

Paolo
Why response.write?
Mitchel Sellers
The problem is that the code doesn't even recognize the " <% %> " tag to incorporate c# on it!
Nicole
@Mitchel - can't remember what the correct syntax is, been doing PHP too long :)
Paolo
+4  A: 

<%= Your VariableNameHere %>

This will output a value to the location you specify.

Mitchel Sellers
+2  A: 

In your code-behind file (assuming you have one), place the following code:

protected string Ruta
{
    get
    {
        TarjetaPL tarjetaPl = null;
        string ruta = null;
        if (Session[Constantes.TarjetaSeleccionada] != null)
        {
            tarjetaPl = new TarjetaPL((Tarjeta)Session[Constantes.TarjetaSeleccionada]);
            ruta = "../../content/images/" + tarjetaPl.TipoDeTarjeta.Banner;
        }
        return ruta;
    }
}

And in your .aspx page, place this code:

<script type="text/javascript">
    swfobject.embedSWF(<%=Ruta %>, "flashBanner", "300", "120", "9.0.0");
</script>
Tim S. Van Haren
A: 

It needs to be treated differently within a <script/> block. Fix it by wrapping your <%=%> blocks with single or double quotes, I tend to use single because sometimes you need to use double quotes within the c# block and it will not be parsed otherwise.

<%
  int number = 1;
  string str = "hi hi";
%>

<script type="text/javascript">
  alert('<%=number%>');
  alert('<%=str%>');
</script>
gum411