【问题标题】:Not able to access input text box value to code behind asp.net c#无法访问输入文本框值到asp.net c#后面的代码
【发布时间】:2018-09-11 09:49:40
【问题描述】:

这是我的页面:

<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>

在 cs 文件中,我尝试使用 cc.Value 访问电子邮件值,因为电子邮件文本框 id 是 cc。但它总是得到空字符串。在我的默认母版页中,我有一个在服务器上运行的表单标签,所以如果我将此模式保存在表单运行服务器中,则会给我错误说页面只能有一个表单标签。请任何人都可以帮助我。提前致谢

【问题讨论】:

  • 尝试使用 和 "email.Text" 没有使用仍然值是空字符串

标签: c# asp.net webforms


【解决方案1】:

这可能会有所帮助Text 属性可用,所以你可以使用textBox.Text 来获取文本框contian。在你的情况下cc.Text

【讨论】:

    【解决方案2】:

    试试textBox.text()。应该可以。

    【讨论】:

      【解决方案3】:

      由于 Html 5 type="email" 控件无法使用 runat 属性,您可以像下面这样访问 TextBox:

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

      现在在代码隐藏中,您可以像 txtBoxCc.Text 一样访问它

      另外,你必须像下面这样写:

      if(!Page.IsPostBack) {
      
          string cc = txtBoxCc.Text;
      } 
      

      【讨论】:

      • 试过 但没用
      • 你有没有放在 !IsPostback 下
      • 另外,能不能把linkbutton改成普通的
      • 检查 ViewState 是否已禁用
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-05
      • 2018-05-24
      • 1970-01-01
      相关资源
      最近更新 更多