我有一个ASP TextBox,其TextMode设置为MultiLine。当用户尝试将换行符放入文本时,我遇到了保留vbCrLf字符的问题。当按下页面上的按钮时,我从控件中取出文本,使用String.Trim对其进行修剪,然后将该值分配给对象的String属性(该属性又将其分配给私有的内部字符串变量在对象上)。然后,该对象从私有内部变量中获取值并使用存储过程调用将其引发到数据库中(它所放入的SP参数是一个nvarchar(4000))。多行文本框中的vbCrLf仅在调用.Trim()时才会显示
ASPX页:
<asp:UpdatePanel ID="UpdatePanel2" runat="server" RenderMode="Inline" UpdateMode="Conditional"
ChildrenAsTriggers="true">
<ContentTemplate>
<!-- some other controls and things -->
<asp:TextBox TextMode="MultiLine" runat="server" ID="txtComments" Width="100%" Height="60px" CssClass="TDTextArea" Style="border: 0px;" MaxLength="2000" />
<!-- some other controls and things -->
</ContentTemplate>
</asp:UpdatePanel>
代码后面:
ProjectRequest.StatusComments = txtComments.Text.Trim
对象属性:
Protected mStatusComments As String = String.Empty
Property StatusComments() As String
Get
Return mStatusComments.Trim
End Get
Set(ByVal Value As String)
mStatusComments = Value
End Set
End Property
存储过程调用:
Common.RunSP(mDBConnStr, "ProjectStatusUpdate", _
Common.MP("@UID", SqlDbType.NVarChar, 40, mUID), _
Common.MP("@ProjID", SqlDbType.VarChar, 40, mID), _
Common.MP("@StatusID", SqlDbType.Int, 8, mStatusID), _
Common.MP("@Comments", SqlDbType.NVarChar, 4000, mStatusComments), _
Common.MP("@PCTComp", SqlDbType.Int, 4, 0), _
Common.MP("@Type", Common.TDSqlDbType.TinyInt, 1, EntryType))
这是最奇怪的部分。当我调试的代码,如果我键入
“测试
测试”
(不带引号)进入评论文本框,然后点击保存按钮,使用即时窗口来查看变量值我一步一步来,这里是我得到的:
?txtComments.Text
"test test"
?txtComments.Text.Trim
"test
test"
?txtComments.Text(4)
"
"c
?txtComments.Text.Trim()(4)
"
"c
任何人都有线索,这是怎么回事?
您有问题或只是想知道发生了什么? – lincolnk 2010-05-13 16:55:35
我检查了它,但在两种情况下都得到了“测试测试” – 2010-05-19 11:46:10