簡體   English   中英

無法訪問輸入文本框值以在asp.net C#之后進行編碼

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

這是我的頁面:

<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。 但是它總是得到空字符串。 在我的默認母版頁中,我有一個在服務器上運行的表單標簽,因此,如果我將此模式保留在表單運行服務器中,則會出現錯誤,提示頁面只能有一個表單標簽。 請任何人能幫助我。 提前致謝

這可能會有所幫助 。提供了Text屬性,因此您可以使用textBox.Text來獲取textbox contian。 在您的情況下cc.Text

試試textBox.text() 應該管用。

由於無法使用runat屬性使用HTML 5 type =“ email”控件,因此您可以如下訪問TextBox:

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

現在在代碼隱藏中,您可以像txtBoxCc.Text一樣訪問它

另外,您必須像下面這樣放置它:

if(!Page.IsPostBack) {

    string cc = txtBoxCc.Text;
} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM