简体   繁体   English

Textbox.text返回空白

[英]Textbox.text returning blank

I have a textbox(txtShipmentDate) that is getting populated with a value selected from a pop-up calendar in the .aspx file. 我有一个文本框(txtShipmentDate),其中填充了一个从.aspx文件中的弹出日历中选择的值。

<tr>
    <td align="right" valign="middle" width="125">
       Shipment Date:
    </td>                                       
    <td align="left" valign="middle">
       <asp:TextBox Runat="server" ReadOnly="true" Width="75" 
           ID="txtShipmentDate" CssClass="textbox"></asp:TextBox>
       <a title="Select Ship Date" onclick="if(self.gfPop)gfPop.fPopCalendar(document.forms[0].txtShipmentDate);return false;"
href="javascript:void(0)">
       <IMG class="PopcalTrigger" height="19" alt="" src="/TOrders/calendarxp/themes/xp/calbtn.gif" width="34" align="absMiddle" border="0"></a>
    </td>
</tr>

The textbox gets populated correctly. 文本框将正确填充。

But when I try to access the value in the textbox when the Submit button is clicked, using 但是当我单击“提交”按钮时尝试访问文本框中的值时,使用

     If txtShipmentDate.Text.Length > 0 Then oShippingDate = Convert.ToDateTime(txtShipmentDate.Text)

the value in the texbox is blank. texbox中的值为空白。 There is nothing else hapenning before the submit. 提交之前,没有其他事情发生。 All other textboxes retain their values. 所有其他文本框保留其值。

Due to security precautions ReadOnly fields do not persist their values upon postback. 由于安全预防措施,ReadOnly字段在回发后不会保留其值。 If you need to prevent user input into this field and still post the value back - do not set textbox'es ReadOnly property. 如果您需要防止用户在此字段中输入内容,并且仍将值回传给他人-请勿设置文本框的ReadOnly属性。 Instead give it a ReadOnly appearance via CSS and then prevent user input thru something like 而是通过CSS为它提供ReadOnly外观,然后阻止用户通过类似

txtShipmentDate.Attributes("onclick") = "this.blur();"

(You may want to handle 'onselect' and 'onpaste' as well). (您可能还需要处理'onselect'和'onpaste')。 This way user input is prevented, giving user complete ReadOnly field appearance and still value is posted back. 这样,可以防止用户输入,从而为用户提供完整的ReadOnly字段外观,并回传静态值。

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

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