I have a FreeTextBox control in my aspx page.
First, the client types the text into the FreeTextBox and click button Save to write the text into Database (sql server 2008).
Then, in Edit function, the text is loaded from Database into FreeTextBox again for Editing.
After Editing, client clicks OK to write the new text into Database but the new text isn't allowed be null or empty.
Take a look at my simple code:
public void btn_OK()
{
if(string.IsNullOrEmpty(FTB.Text))
Labelerror.Text="The text cannot be null or empty.";
else
{
...write new text into Database...
}
}
Building: when I clear the old text and click OK, the program passes the if statement and does the codes inside else statement (write new text into Database).
Try to debug, I clear the old text and let the FreeTextBox empty but the FTB.Text= "<p class=\"MsoNormal\"><br></p>"
Where is the <p class=\"MsoNormal\"><br></p>from???
As recommended, I use HttpUtility.HtmlDecode to decode that html tag:
string text= HttpUtility.HtmlDecode(FTB.Text);
if(string.IsNullOrEmpty(text))
But nothing change: text= "<p class=\"MsoNormal\"><br></p>"
Help!!! How can I remove that html tag to check if the FreeTextbox is null or empty.
Related
I am looking for a simple script that would basically do the equivalent of a user pressing Ctrl+A (select all) on a web page and then copying the text to the clipboard so I can pull it into a string from there.
The reason I want to emulate a user selecting all and then copy and pasting is because some pages are generated with Javascript and do not have the visible text in the HTML.
In any case, I am just looking for the raw unparsed text. I do not care if the spacing/line breaks are messed up, etc. I just want a quick and dirty snapshot of all the selectable text on the page into a string.
I have tried doing below as an example:
private void button3_Click(object sender, EventArgs e)
{
HAP.HtmlWeb web = new HAP.HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.
Load(#"https://mywebsite");
string str = doc.DocumentNode.InnerText;
MessageBox.Show(str);
}
but if the page has javascript it does not return the text displayed by it.
Instead of
doc.DocumentNode.InnerText;
Use this
doc.DocumentNode.InnerHtml;
It will get you the whole HTML including JS and CSS. Hope it helps.
With jQuery: $(document).text() or $('body').text()
I have an asp.net web form which on one page has a multi line textbox. When the user types in this field and continues the details are displayed on a confirmation page and displays as the user entered
Example
This is the first line
This is the second line
But when I click my edit button (which directs me back to my page) my textbox displays as
This is the first line<br /><br />This is the second line
I want it to keep its styling but don't know how to do this. The details are stored in the session.
Code behind
protected void Step07SubmitButton_Click(object sender, EventArgs e)
{
Session["Step07OtherDetailsField"] = Step07OtherDetailsField.Text.Replace("\r\n", "<br />");
Response.Redirect("/Quotation/pg3.aspx");
}
I tried the following in my Page_Load
Step07OtherDetailsField.Text.Replace("<br />", "\r\n");
and also
Step07OtherDetailsField.Text.Replace("<br />", Environment.NewLine);
But for some reason when I debug it, it says that my .text is empty but the previous wording is actually still displayed in the field and the <br /> is also still displayed.
You don't need to replace anything. You just store value in session and display it to any textbox, it will maintain \r and \t.
If you want to display result in span then display result to textbox with multiline then apply css for no border,etc.
I am working on asp.net mvc. I am trying to save form-data to the database. I have the form with one textarea where user can type the text or he can paste the text from somewhere. Here i need to save the text of textarea into database. and then i need to show the textarea content what he saved,
#using (Html.BeginForm("myaction", "mycontrolller", FormMethod.Post,
new { id = "addform" }))
{
<textarea id="note" name="note"></textarea>
<input type="submit"/>
}
Now i am able to get the data that user entered into my post action from view, But the text doesn't contain any line breaks or carriage returns though he pasted multiple paragraph text. While i am in debugging and watch the text content in Text Visualizer, it shows me with exact format. But when i save it into the database. It save it as single line of text and so shows me as a single line of text, when i displayed.
I have tried the following code,
obj.Notes = obj.Notes
.Replace(Environment.NewLine, "<br />")
.Replace("\r\n", "<br />");
But it doesn't resolve my problem. It still displays single line of continuous text though it have multi-paragraph text.
Yes I've got solution to my answer after a small trial, just displayed the content in <pre> tag instead of <p>
Replaced from:
<p>Data from Database</p>
to
<pre>Data from Database</pre>
<FTB:FreeTextBox id="NOI_DUNG" runat="server"
EditorBorderColorDark="DarkGray" EditorBorderColorLight="DarkGray"
Width="100%" GutterBorderColorDark="Gray" GutterBorderColorLight="White"
ToolbarStyleConfiguration="OfficeMac" AutoGenerateToolbarsFromString="True"
ToolbarImagesLocation="InternalResource"
JavaScriptLocation="InternalResource"
ButtonImagesLocation="InternalResource"
ImageGalleryUrl="aspnet_client/ftb.imagegallery.aspx?rif=/imagespath/&cif=../upload/imagesupload/"
ImageGalleryPath="/upload/imagesupload/" SupportFolder="../aspnet_client/FreeTextBox/" />
I also have a table in SQL database:
NOTICE(num,title,content [allow null])
I have 1 textbox to input: title, and 1 FreeTextBox to input content.
The first time, I input both title and content->click button "INSERT"--> work fine
The twice, I just imput only title and I let the content empty-->click button "INSERT"-->the field content in Database is auto filled with the old content of the first input time.
I really dont know why. The only way, I think I shoul Reset(clean) the textfield of FreeTextBox when page load?
I am interested in saving text when user selects any text anywhere on a web page that text has to be highlighted and has to save that text as a string in C#.
when same user saw same page next time text has to be highlighted as done previously by him.
If anyone knows a simple elegant way to do this I would really appreciate it, but I'll take any solution at this point. Even if you can point me in the right directions that would be appreciated.
Thanks in advance.
You need to write service WCF or Webservice in server side that will receive userId and text and save it into database.
[WebMethod(Description = "Save Text")]
public string Savetext(int userId ,string text)
{
}
Second method will retrive the text from daatabase by user id
[[WebMethod(Description = "Get text")]
public string GetText(int userId)
{}
In client side do invokation using Ajax calls (Jquery)
Use this to get selected text from page: http://mark.koli.ch/2009/09/use-javascript-and-jquery-to-get-user-selected-text.html
Then in mouseup event copy it to some HiddenField. Now you need a button or maybe AJAX call in mouseup so you can send it to server. On the server side save it to DB along with UserID and page address or ID.
On the next visit of this user to this page check in DB for entry. If it exist put the text in some hidden field. Then using jQuery get that text clientside, find it on page (using regex or something) and select it. You should remember to disregard any HTML markup while finding the text which can be tricky...
That is general way I would take to do this.
you can do that by capturing the selected text and send it via ajax call to your database.
check this example to know haw you can capture the selected text.
If you use jquerythen you will use select() function to capture the selected text
<textarea id="txt"></textarea>
<script>
$(document).ready(function(){
$('textarea').select(function()
{
var selectedText=window.getSelection();
//here put the ajax call to your webservice
});
});
</script>