简体   繁体   English

无法访问输入文本框值以在asp.net C#之后进行编码

[英]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. 在cs文件中,我尝试使用cc.Value访问电子邮件值,因为电子邮件文本框ID为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. 这可能会有所帮助 。提供了Text属性,因此您可以使用textBox.Text来获取textbox contian。 In your case cc.Text . 在您的情况下cc.Text

Try textBox.text() . 试试textBox.text() Should work. 应该管用。

As Html 5 type=“email” control is not available using runat attribute, you can access TextBox like below: 由于无法使用runat属性使用HTML 5 type =“ email”控件,因此您可以如下访问TextBox:

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

Now in codebehind you can access it like txtBoxCc.Text 现在在代码隐藏中,您可以像txtBoxCc.Text一样访问它

Also, you have to put it like below: 另外,您必须像下面这样放置它:

if(!Page.IsPostBack) {

    string cc = txtBoxCc.Text;
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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