asp: PlaceHolder and JavaScript

0

I'm working on a project in which I'm using asp: PlaceHolder and this tag contains a radiobuttonlist , but this radiobuttonlist is not working from HTML but rather what handling from the C #.

The question I have is: Is it possible to access the raddiobuttonlist through JavaScript? If so, how can I do it?

This is my code:

HTML

<asp:PlaceHolder runat="server" ID="phdejemplo"></asp:PlaceHolder>

C #

private void RadioButtonEjemplo(Pregunta pregunta, bool esVisible)
    {
        var rblRespuestasEjemplo = new RadioButtonList();
        rblRespuestasEjemplo.ID = "rblPregunta" + pregunta.PreguntaId;
        rblRespuestasEjemplo.Visible = esVisible;
        rblRespuestasEjemplo.RepeatDirection = pregunta.ModoVisualizacion ? RepeatDirection.Vertical : RepeatDirection.Horizontal;
        rblRespuestasEjemplo.AutoPostBack = true;
        rblRespuestasEjemplo.SelectedIndexChanged += (sender, e) => rblRespuestasEjemplo_SelectedIndexChanged(sender, e, pregunta.PreguntaId);

        phdejemplo.Controls.Add(rblRespuestasEjemplo);

    }

private void rblRespuestasEjemplo_SelectedIndexChanged(object sender, EventArgs e, int preguntaId)
    {
        RadioButtonList radio = (RadioButtonList)sender;
        var respuestaSeleccionadaId = Convert.ToInt32(radio.SelectedValue);
    }

What I want to do with the JavaScript is to know if a radiobutton was selected.

Thank you in advance.

    
asked by Juan Alzate 25.09.2018 в 16:08
source

1 answer

0

How about something like this on your button or other object:

OnChange="javascript:CogeRegistro();return false;" If there is a change

OnClick ="javascript:MiRutina();" If they click

It's a way to call your javaScript function from the button itself.

I use it that way, but I suggest that you change JQuery little by little.

You can write it from the back code in C #, that is, you force the back code to write whatever you want inside the page in the PlaceHolder or wherever you want. The code would be something like:

PlaceMenu.Controls.Add(new LiteralControl("<Escribe aquí... el código HTML o el botón, o...>"));

Then in addition to writing it, you access it from javascript, c # or whatever you need.

    
answered by 25.09.2018 в 17:16