1

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!

4 Answers 4

4

This will output a value to the location you specify.

Sign up to request clarification or add additional context in comments.

Comments

3

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

2 Comments

The problem is that the code doesn't even recognize the " <% %> " tag to incorporate c# on it!
@Mitchel - can't remember what the correct syntax is, been doing PHP too long :)
2

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>

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.