How to take the content of a textarea and show in a modal

Asked

Viewed 195 times

0

I wonder if I can take the content of a textarea (which in this case is a Texbox) and show in a modal, in my case:

Follow the code I made:

<asp:Label runat="server" CssClass="text-bold" Text="Informe as unidades a serem verificadas"></asp:Label>
<asp:TextBox TabIndex="1" runat="server" ID="txtDevice" CssClass="input-sm form-control" placeholder="Unidade" TextMode="MultiLine" Height="120px" />
<asp:RequiredFieldValidator SetFocusOnError="true" runat="server" ControlToValidate="txtDevice" CssClass="text-danger" ErrorMessage="Campo obrigatório!" ValidationGroup="btnBuscar" Display="Dynamic" />

and further down in the same file, the modal (which I call when I click a button)

<div class="modal fade" id="modalPointerCargo" tabindex="-1" role="dialog" aria-labelledby="modalPointerCargo" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content panel-padrao">
            <div class="modal-header">
                <h5 class="modal-title">Modal title</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <i aria-hidden="true" class="glyphicon glyphicon-remove"> </i>
                </button>
            </div>

            <div class="modal-body">
                QUERO MOSTRAR O CONTÉUDO DO CAMPO AQUI
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-primary">Save changes</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

How could I do that?

1 answer

0

Are you using Webform? If yes you should do the assignment in the back end of the page, as follows:

Front end:

 <asp:TextBox runat="server" ID="txtData"></asp:TextBox><br />

Back end:

protected void Page_Load(object sender, EventArgs e)
  {

     txtData.Text = "Seu texto";

  }

You can add a new label in your modal, "txtmodal" and in the back end you do the assignment, in the event you want:

protected void seuBotao_Click(object sender, EventArgs e)
{

    txtmodal.Text = txtDevice.Text;
}

EDIT: To understand the behavior, run the following test:

Create a new project and in the Default.aspx file, swap all the contents of the tag <asp:Content> to the following:

<asp:Label ID="Label1" runat="server" Text="teste"></asp:Label><br />
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />
    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

The button event should look like this:

protected void Button1_Click(object sender, EventArgs e)
        {
            Label2.Text = Label1.Text;
        }

If you test it you will see that the label2 text is replaced by the label1 text. Understanding this behavior you can adjust your project to work.

  • I did what you told me, but it didn’t work, would it be something like that? (I’m asking very simple questions because I’m starting the studies of it this week) <div class="modal-body"> <Asp:Label runat="server" ID="txtModal"></Asp:Label> </div> and the back end protected void Buttonpc_click(Object Sender, Eventargs and) { txtModal.Text = txtDevice.Text; }

  • That’s right, I’ll edit the answer so you can take a test.

  • Did the answer help solve the problem and can it solve similar questions from other users? If so, don’t forget to mark the answer as accepted. To do this just click on the left side of it (below the indicator of up and down votes).

Browser other questions tagged

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