asp.net how to change the SVG image in html page from the codebehind

0

I need to change the image (SVG) that is on the page in a object container by selecting another item within dropdownlist. It has to be in the CodeBehind, using the OnSelectedIndexChanged event. By default it loads the image.svg, but when selecting another dropdownlist item it would have to change, loading another image that is stored in the same directory.

The code of the aspx is:

<td class="auto-style24" style="vertical-align: top;">
                Punto de Medición<br />
                <asp:DropDownList ID="DDLPuntoMedicion" runat="server" DataSourceID="EDFPtoMedicion" DataTextField="Nombre" DataValueField="Id" Width="150px" Height="25px" OnPreRender="DDLPuntoMedicion_PreRender" AutoPostBack="True" OnSelectedIndexChanged="DDLPuntoMedicion_SelectedIndexChanged">
                </asp:DropDownList>
                 </td>
            <td >
                 </td>
        </tr>
        <tr>
            <td class="auto-style24" style="vertical-align: top; text-align: center;">
                <object id="diagrama" type="image/svg+xml" data="Imagen/Imagen.svg" style="border: medium ridge #C0C0C0; width: auto; height: 480px;"></object>
            </td>
            <td >

The code in C # should be inside:

protected void DDLPuntoMedicion_SelectedIndexChanged(object sender, EventArgs e)
        {


        }
    
asked by PabloB 12.02.2017 в 19:54
source

1 answer

1

Your question seems simple, but it is more complicated than it seems.

In principle the typical solution to add a runat=server in the html does not work because in asp.net there is no htmlcontrol "object".

I will give you a couple of solutions ... choose the one you like ...

If you define the Object like this

<object id="diagrama" type="image/svg+xml" data="<%=PropiedadPublicaDelFormulario" style="border: medium ridge #C0C0C0; width: auto; height: 480px;"></object>

In the code you would need a

public string PropiedadPublicaDelFormulario{ get; set; }

Then in SelectedIndexChanged you simply give a value to PropertyPublicaDelFormulario and the value Object should be changed.

Other solutions go through using a PlaceHolder control instead of the Object, and in the event create a LiteralControl or HtmlGenericControl manually.

    
answered by 24.02.2017 / 12:17
source