Use freetextbox control in Asp.net

Source: Internet
Author: User

These two days I have been learning how to use the freetextbox webpage text editor. I have found a lot on the Internet, but it is not very detailed. Below I take FreeTextBox-3.1.6 as an example to describe how to use this control and give an instance.

 

Step 1: unzip the FreeTextBox-3.1.6 as long as the freetextbox. DLL, Ftb. imagegallery. copy the aspx and aspnet_client folders to the project folder and test. aspx is in the same directory, where freetextbox. DLL is put in the bin folder and added reference in vs2008 (in fact, freetextbox. DLL does not need to be copied to the project folder. You only need to "solution-> right-click-> Add reference" and the bin folder will automatically generate freetextbox. DLL ).

Step 2: Make freetextbox a space and add it to the toolbox. this is written in the previous blog. Click here to view details.

Step 3: add the control freetestbox to the aspx file and modify its attributes. The modified control attributes are as follows:

<Ftb: freetextbox id = "free1" <br/> imagegallerypath = "~ /Images "<br/> Language =" ZH-CN "runat =" server "<br/> buttondownimage =" true "<br/> toolbarlayout =" paragraphmenu, fontfacesmenu, fontsizesmenu, <br/> delimiter, fontforecolorpicker, delimiter, <br/> fontbackcolorpicker | bold, italic, underline, strikethrough, superscript, <br/> subscript, removeformat | justifyleft, justifyright, <br/> justifycenter, justifyfull; bulletedlist, numberedlist, indent, outdent; CreateLink, unlink, <br/> insertimage | cut, copy, paste, delete; UNDO, redo, print, save | symbolsmenu, stylesmenu, <br/> inserthtmlmenu | insertrule, insertdate, inserttime | inserttable, edittable; values, <br/> values, deletetablerow; values, values, <br/> deletetablecolumn | insertform, inserttextbox, struct, struct, <br/> insertcheckbox, insertdropdownlist, insertbutton | insertdiv, editstyle, inline, <br/> preview, selectall, wordclean, netspell "> <br/> </Ftb: freetextbox>

Step 4:

Set Properties in Ftb. imageegallery. aspx

<Ftb: imagegallery id = "imagegallery1" supportfolder = "~ /Aspnet_client/freetextbox/"<br/> allowimagedelete =" true "allowimageupload =" true "<br/> allowdirectorycreate =" true "allowdirectorydelete =" true "runat =" server "/>

These attributes allow you to delete images and upload images, create folders, and delete folders.

Note:

After completing the above steps, we will go to test. in the design view of aspx, you still cannot see the text editor buttons. You can only see the blank interface "freetextbox: free1". I thought the operation was not successful, so the above steps have been repeated many times, but they are still like this. Later I opened them in a browser and found that the operation was successful. I did a lot of useless work before. Haha.

Instance

In the aspx file, add another testbox Post "title" and a button "Submit ".

Test. aspx. CS:

Protected void btnsubmit_click (Object sender, eventargs e) <br/>{< br/> String title = This. textbox1.text; <br/> string content = This. free1.text; <br/> newsbus. addnews (title, content); <br/> // response. redirect (""); <br/> content = newsbus. getlatenews (). tables [0]. rows [0] [2]. tostring (); <br/> response. write (content); // output the content of the newly inserted news <br/>}

 

Newsbus. CS in appcode:

Public static bool addnews (String title, string content) <br/>{< br/> string strsql = "insert into test (title, content) values (@ title, @ content) "; <br/> sqlparameter [] paras = new sqlparameter [2]; <br/> paras [0] = new sqlparameter (" @ title ", sqldbtype. varchar); <br/> paras [0]. value = title; </P> <p> paras [1] = new sqlparameter ("@ content", sqldbtype. varchar); <br/> paras [1]. value = content; </P> <p> If (newsdb. getcmd (strsql, paras) <br/>{< br/> return true; <br/>}< br/> return false; <br/>}< br/> Public static dataset getlatenews () <br/>{< br/> string strsql = "select top 1 * from test order by id desc "; <br/> return newsdb. getds (strsql); <br/>}

Newsdb. CS in appcode:

Public static sqlconnection creatcon () <br/>{< br/> string STR = configurationmanager. deleetask[ "conn"]; <br/> return New sqlconnection (STR); <br/>}< br/> Public static dataset getds (string strsql) <br/> {<br/> sqlconnection con = newsdb. creatcon (); <br/> dataset DS = NULL; <br/> try <br/> {<br/> sqldataadapter da = new sqldataadapter (strsql, con ); <br/> DS = new dataset (); <br/> da. fill (DS); <br/>}< br/> catch (exception ER) <br/>{< br/> throw er; <br/>}< br/> return Ds; <br/>}

Web. config

<Configuration> <br/> <etettings> <br/> <add key = "conn" value = "Data Source = xuwei/sqlexpress; initial catalog = testdatabase; user ID = dnndemo; Password = dnndemo "/> <br/> </appsettings> <br/> </configuration>

 

Finally, Enter text in the title and content bar, add an image, and click "Submit". The entered content is displayed. This includes images.

In fact, the principle is very simple. After we input the text in the content bar to a specified field in the database, freetextbox will judge whether we have inserted images,

If an image exists, the image address is also written into the "content" field.

For example, in the freetextbox text box, enter the text "content bar, insert an image", and then insert a text file named "pic.jpg ", after "Submission" is complete, go to the database table test and check the content of the field as follows:

<P> content bar, insert an image </P> <br/> <p> </P> <br/>

In the images directory, we can also find the inserted image "pic.jpg ". This is caused

<Ftb: freetextbox id = "free1" <br/> imagegallerypath = "~ /Images "... <br/> </Ftb: freetextbox>

.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.