我有一个将textmode设置为multiline的ASP文本框。当用户试图在文本中插入换行符时,我在保留vbcrlf字符方面遇到了问题。当按下页面上的按钮时,我将从控件中提取文本,使用string.trim对其进行剪裁,并将该值赋给对象上的string属性(该属性又将其赋给对象上的私有内部字符串变量)。然后,该对象从私有内部变量中获取值,并使用存储过程调用(将其放入的sp参数是nvarchar(4000))将其抛出到数据库中。
ASPX Page:
<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
有人知道这是怎么回事吗?