Retrieving values from my form

Asked

Viewed 452 times

0

I am trying to recover the values of a form. This is the correct way to retrieve them to pass to 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 the values from the form

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);
}

1 answer

2

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

  • The runat="server" in , is missing or the address of where you want to arrive with the Submit of this form. That is action and the method
  • Runat="server" is missing on the button, or switch to ASP.NET input or Button, or type="Submit" with onserverclick="Event".

You can try putting on that modal of yours, which you don’t have runat="server", within a Usercontrol.

In your Visual Studio create a new Web User Control type file. So: http://prntscr.com/4pmmhr

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

  • So you’re going to put all this code just what’s inside the .
  • Then you need to create a button with the method call you want, for example EnviarClick sei there.
  • After that puts all your "recovery" code of the values within this method.

Your User Control will look like this:

Code-Behind: http://prntscr.com/4pmsl5

HTML/ASP.NET: http://prntscr.com/4pmqo2

Web config: http://prntscr.com/4pms1t

P/ use it: http://prntscr.com/4pmto7

  • The problem with using runat is that I can only use one <form runat="server">, and I’m already using it. That’s why I’m after another way to recover the values of this modal.

  • Bruno, can you give me a hand here?

  • 1

    Could you bring these images to the site? These links may become invalid over time and response will also stay.

  • I can’t do it anymore! my C# Workspace has been removed from my machine, but I took the advice! thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.