如何在asp.net中使用FreeTextBox控件
步驟一:解壓FreeTextBox-3.1.6只要將FreeTextBox.dll、ftb.imagegallery.aspx和aspnet_client文件夾拷貝到項(xiàng)目文件夾中,和我們的test.aspx在相同的目錄下中,其中FreeTextBox.dll放到bin文件夾下并且在VS2008中添加引用(其實(shí)FreeTextBox.dll不需要拷貝進(jìn)項(xiàng)目文件夾,只需要"解決方案->右鍵->添加引用"后bin文件夾中會(huì)自動(dòng)產(chǎn)生FreeTextBox.dll)。
步驟二:將FreeTextBox做成空間添加到工具箱中,這在前一篇文章中寫過,點(diǎn)擊進(jìn)入查看。
步驟三:往aspx文件中添加控件FreeTestBox,并修改其屬性。修改后的控件屬性如下:
<FTB:FreeTextBox ID="Free1"
ImageGalleryPath="~/Images"
Language="zh-CN" runat="server"
ButtonDownImage="True"
toolbarlayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,
FontForeColorsMenu,FontForeColorPicker,FontBackColorsMenu,
FontBackColorPicker|Bold,Italic, Underline,Strikethrough,Superscript,
Subscript,RemoveFormat|JustifyLeft,JustifyRight,
JustifyCenter,JustifyFull;BulletedList,NumberedList,Indent,Outdent;CreateLink,Unlink,
InsertImage|Cut,Copy,Paste,Delete;Undo,Redo,Print,Save|SymbolsMenu,StylesMenu,
InsertHtmlMenu|InsertRule,InsertDate,InsertTime|InsertTable,EditTable;InsertTableRowAfter,
InsertTableRowBefore,DeleteTableRow;InsertTableColumnAfter,InsertTableColumnBefore,
DeleteTableColumn|InsertForm,InsertTextBox,InsertTextArea,InsertRadioButton,
InsertCheckBox,InsertDropDownList,InsertButton|InsertDiv,EditStyle,InsertImageFromGallery,
Preview,SelectAll,WordClean,NetSpell" >
</FTB:FreeTextBox>
步驟四:在 ftb.imageegallery.aspx 中設(shè)置屬性
<FTB:ImageGallery id="ImageGallery1" SupportFolder="~/aspnet_client/FreeTextBox/"
AllowImageDelete="true" AllowImageUpload="true"
AllowDirectoryCreate="true" AllowDirectoryDelete="true" runat="Server" />
這些屬性表示允許刪除圖片和上傳圖片,允許創(chuàng)建文件夾和刪除文件夾 。
注意:
完成以上這些,我們?cè)趖est.aspx的設(shè)計(jì)視圖下,還是無法看到那些文本編輯器按鈕,只能看到的是“FreeTextBox:Free1”這么一個(gè)空白界面,原本我以為沒有操作成功,所以上面的步驟重復(fù)了好多次,但依舊是這樣,后來在瀏覽器下打開發(fā)現(xiàn)原來操作已經(jīng)成功了,前面做了很多無用功。呵呵。
實(shí)例
在aspx文件中再添加一個(gè)TestBox做文章的“標(biāo)題”,一個(gè)按鈕Button“提交”。
test.aspx.cs:
protected void btnSubmit_Click(object sender, EventArgs e)
{
string title = this.TextBox1.Text;
string content = this.Free1.Text;
NewsBus.AddNews(title,content);
//Response.Redirect("");
content = NewsBus.getLateNews().Tables[0].Rows[0][2].ToString();
Response.Write(content);//輸出最新插入的那條新聞的內(nèi)容
}
appcode中NewsBus.cs:
public static bool AddNews(string title ,string content)
{
String strsql = "Insert into test(title,content) Values(@title,@content)";
SqlParameter[] paras = new SqlParameter[2];
paras[0] = new SqlParameter("@title", SqlDbType.VarChar);
paras[0].Value =title;
paras[1] = new SqlParameter("@content", SqlDbType.VarChar);
paras[1].Value =content;
if (NewsDB.Getcmd(strsql, paras))
{
return true;
}
return false;
}
public static DataSet getLateNews()
{
string strsql = "select top 1 * from test order by id desc";
return NewsDB.Getds(strsql);
}
appcode中NewsDB.cs:
public static SqlConnection CreatCon()
{
string str=ConfigurationManager.AppSettings["conn"];
return new SqlConnection(str);
}
public static DataSet Getds(String strsql)
{
SqlConnection con=NewsDB.CreatCon();
DataSet ds= null;
try
{
SqlDataAdapter da = new SqlDataAdapter(strsql, con);
ds = new DataSet();
da.Fill(ds);
}
catch (Exception er)
{
throw er;
}
return ds;
}
web.config
<configuration>
<appSettings>
<add key="conn" value="Data Source=XUWEI/SQLEXPRESS;Initial Catalog=TestDatabase;User ID=dnndemo;Password=dnndemo" />
</appSettings>
</configuration>
最后在標(biāo)題和內(nèi)容欄中輸入文字,并且添加圖片,點(diǎn)擊“提交”以后會(huì)顯示剛輸入的內(nèi)容。其中就包括圖片。
其實(shí)原理很簡(jiǎn)單,F(xiàn)reeTextBox在我們將內(nèi)容欄中的文本輸入到數(shù)據(jù)庫的指定字段以后,會(huì)判斷我們有沒有插入圖片,
如果有圖片則將圖片的地址也寫入“內(nèi)容”字段中。
比如我們?cè)贔reetextBox的文本框中輸入文本:“內(nèi)容欄,插入圖片”,然后再插入一個(gè)叫做"pic.jpg","提交"完成以后我們?nèi)?shù)據(jù)庫的表test中看字段content的內(nèi)容如下:
<P>內(nèi)容欄,插入圖片</P>
<P><IMG height=366 alt=未命名.jpg src="/testFTB3/Images/pic.jpg" mce_src="testFTB3/Images/pic.jpg" width=950 border=0></P>
而在Images目錄下我們也能找到剛才插入的圖片"pic.jpg"。這個(gè)是由
<FTB:FreeTextBox ID="Free1"
ImageGalleryPath="~/Images" ...
</FTB:FreeTextBox>
相關(guān)文章
asp.net 1.1/ 2.0 中快速實(shí)現(xiàn)單點(diǎn)登陸
asp.net 1.1/ 2.0 中快速實(shí)現(xiàn)單點(diǎn)登陸...2007-04-04
ASP.NET MVC學(xué)習(xí)教程之Razor語法
這篇文章主要給大家介紹了關(guān)于ASP.NET MVC學(xué)習(xí)教程之Razor語法的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-05-05
Repeater事件OnItemCommand取得行內(nèi)控件的方法
這篇文章主要介紹了Repeater事件OnItemCommand取得行內(nèi)控件的方法,有需要的朋友可以參考一下2014-01-01
asp.net MVC使用PagedList.MVC實(shí)現(xiàn)分頁效果
這篇文章主要為大家詳細(xì)介紹了asp.net MVC使用PagedList.MVC實(shí)現(xiàn)分頁效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
asp.net中將數(shù)據(jù)庫綁定到DataList控件的實(shí)現(xiàn)方法與實(shí)例代碼
我現(xiàn)在要做這個(gè)頁面,然后我用DataList控件顯示題目,我想問如何把我數(shù)據(jù)庫的題目綁定到DataList控件里面,然后讓它顯示考試題目?2011-06-06
解決.Net Core項(xiàng)目發(fā)布在IIS上訪問404的問題
這篇文章介紹了解決.Net Core項(xiàng)目發(fā)布在IIS上訪問404的問題,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-12-12
asp.net中js+jquery添加下拉框值和后臺(tái)獲取示例
這篇文章主要介紹了asp.net中js+jquery添加下拉框值和后臺(tái)獲取的具體實(shí)現(xiàn),需要的朋友可以參考下2014-05-05
jquery中如何獲得服務(wù)器控件實(shí)現(xiàn)思路
jquery中如何獲得服務(wù)器控件,很多新手朋友對(duì)此比較陌生,接下來為您介紹解決方法,感興趣的朋友可以了解下哦2013-01-01

