简体   繁体   中英

Not able to access input text box value to code behind asp.net c#

Here my page :

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

<%@ Register Assembly="Microsoft.ReportViewer.WebForms" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>




        <asp:HiddenField ID="hdnfromDate" Value="" runat="server" />
        <asp:HiddenField ID="hdntoDate" Value="" runat="server" />
        <div id="myModal1" class="modal fade" role="dialog">
            <div class="modal-dialog">

                <!-- Modal content-->
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">Issue Invoice</h4>
                        <button type="button" class="close" data-dismiss="modal">×</button>

                    </div>
                    <div class="modal-body">

                        <form id="reused_form" runat="server">
                            <p>
                                Send invoice to...
                            </p>

                            <div class="form-group">
                                <label for="name">
                                    To:</label>
                                <input type="text" class="form-control"
                                    id="name" name="name" readonly maxlength="50" runat="server">
                            </div>
                            <div class="form-group">
                                <label for="email">
                                    CC:</label>

                                <input type="email" ID="cc" class="form-control" runat="server" multiple>
                            </div>
                            <div class="form-group">
                                <strong><i>Note:</i><small>&nbsp<i>The invoice can not be edited after issuing.</i></small></strong>
                            </div>


                            <asp:LinkButton CssClass="btn btn-warning m-btn btn-block btn-lg m-btn--custom m-btn--icon m-btn--air  " OnClick="Onbtn3_Click" Text="Issue Invoice " ID="LinkButton3" runat="server"></asp:LinkButton>
                        </form>
                        <div id="success_message" style="width: 100%; height: 100%; display: none;">
                            <h3>Sent your message successfully!</h3>
                        </div>
                        <div id="error_message"
                            style="width: 100%; height: 100%; display: none;">
                            <h3>Error</h3>
                            Sorry there was an error sending your form.

                        </div>
                    </div>

                </div>

            </div>
        </div>

In cs File i am trying to access email value using cc.Value as for email textbox id is cc. But it always gets empty string. In my default master page i have a form tag which runs at server so if i keep this modal in a form runat server then gives me error saying page can have only one form tag. Please can anyone help me out. Thanks in advance

This may help There is Text property available, so you can use textBox.Text to get textbox contian. In your case cc.Text .

Try textBox.text() . Should work.

As Html 5 type=“email” control is not available using runat attribute, you can access TextBox like below:

<asp:TextBox ID="txtBoxCc" runat="server" TextMode="Email"></asp:TextBox>

Now in codebehind you can access it like txtBoxCc.Text

Also, you have to put it like below:

if(!Page.IsPostBack) {

    string cc = txtBoxCc.Text;
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM