Storing a column in a variable
I wanted a formatted text to be converted into unformatted text in the UI . for that I did the following
String strInput;
String strOutput;
strInput = txtEditorAnswer.Text;
strOutput = Regex.Replace(strInput, "<[^>]*>", String.Empty).Trim();
txtEdi开发者_C百科torAnswer.Text = strOutput;
txtEditorAnswer.Text = Server.HtmlEncode(txtEditorAnswer.Text);
but as it changes the value in the Database also, so its creating a problem for future. Now I need to change the text after being inserted into the database. What should I do?
Your use case isn't clear, but I'll assume you want the "Tagged" text when the txtEditorAnswer
has focus, and the "UnTagged" text when focus moves away.
In this case, you could attach a property to txtEditorAnswer
, let's call it RawText
.
On Init:
var text = GetTextFromDatabase();
txtEditorAnswer.RawText = text;
txtEditorAnswer.Text = Regex.Replace(text, "<[^>]*>", String.Empty).Trim();
On Focus:
txtEditorAnswer.Text = txtEditorAnswer.RawText;
On LostFocus:
txtEditorAnswer.RawText = txtEditorAnswer.Text;
SaveToDatabase(txtEditorAnswer.RawText);
txtEditorAnswer.Text = Regex.Replace(txtEditorAnswer.Text, "<[^>]*>", String.Empty).Trim();
(Refactor as appropriate).
Or, as @Andomar points out, you could have a second control that is your "preview" of the text being entered into txtEditorAnswer
.
精彩评论