Retrieving the values from my form

0

I'm trying to retrieve the values of a form. Is this a good way to get them back to get through my DAL?

<div id="myModal_Veiculos" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <form id="Cad_Veiculos">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3>Cadasto de Clientes</h3>
        </div>
        <div class="modal-body">
                <label>Modelo </label><input type="text" name="modelo" id="modelo" />
                <label>Placa </label><input type="text" id="placa" name="placa" />
                <label>Quilometragem </label><input type="text" id="quilometragem" name="quilometragem" />
                <label>Cor </label><input type="text" name="cor" id="cor" />
                <label>Tipo </label><input type="text" name="tipo" id="tipo" />
                <label>Ano </label><input type="text" name="ano" id="ano" />
                <label>Chassi </label><input type="text" name="chassi" id="chassi" />
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Fechar</button>
            <Button class="btn btn-primary" onclick="button1_cad_veiculo">Salvar</Button>
        </div>
        </form>
    </div>

Retrieving form's values

protected void button1_cad_veiculo(object sender, EventArgs e)
{
    Veiculo vl = new Veiculo();

    vl.Modelo1 = Request.Form["modelo"];
    vl.Quilometragem1 = Request.Form["quilometragem"];
    vl.Placa = Request.Form["placa"];
    vl.Cor = Request.Form["cor"];
    vl.Chassi = Request.Form["chassi"];
    vl.Tipo = Request.Form["tipo"];

    VeiculoDAL.cadastra(vl);
}
    
asked by anonymous 23.09.2014 / 05:57

1 answer

2

Recovering you will recover, your problem is how to get an event to reach your treatment.

  • The runat="server" is missing, or the address where you want to go with the submit of this form is missing. That is action and method
  • The runat="server" is missing on the button, or switch to the ASP.NET button or input submit, or type="submit" with the onserverclick="event".

You can try putting your mod, which does not have runat="server" , within a UserControl.

In your Visual Studio creates a new file of type Web User Control. Like this: link

What will happen this file will be used as if it were an HTML tag, but different slightly, look for more about it on the internet, it is very useful!

  • So you're going to put all that code inside what's inside.
  • There you need to create a button with the method call you want, for example EnviarClick sei there.
  • After that, you put all your "recovery" code values into this method.

Your User control will look like this:

Code-behind: link

HTML / ASP.NET: link

Web config: link

To use it: link

    
23.09.2014 / 06:26