如何在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做成空間添加到工具箱中,這在前一篇文章中寫(xiě)過(guò),點(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ì)視圖下,還是無(wú)法看到那些文本編輯器按鈕,只能看到的是“FreeTextBox:Free1”這么一個(gè)空白界面,原本我以為沒(méi)有操作成功,所以上面的步驟重復(fù)了好多次,但依舊是這樣,后來(lái)在瀏覽器下打開(kāi)發(fā)現(xiàn)原來(lái)操作已經(jīng)成功了,前面做了很多無(wú)用功。呵呵。
實(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ù)庫(kù)的指定字段以后,會(huì)判斷我們有沒(méi)有插入圖片,
如果有圖片則將圖片的地址也寫(xiě)入“內(nèi)容”字段中。
比如我們?cè)贔reetextBox的文本框中輸入文本:“內(nèi)容欄,插入圖片”,然后再插入一個(gè)叫做"pic.jpg","提交"完成以后我們?nèi)?shù)據(jù)庫(kù)的表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中Core自定義View查找位置的實(shí)例代碼
在本篇文章里小編給大家分享的是關(guān)于ASP.net中Core自定義View查找位置的實(shí)例代碼,需要的朋友們可以學(xué)習(xí)下。2020-04-04詳解ASP.NET Core 中的框架級(jí)依賴(lài)注入
本篇文章主要介紹了詳解ASP.NET Core 中的框架級(jí)依賴(lài)注入,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10.NET微信公眾號(hào)獲取OpenID和用戶(hù)信息
這篇文章主要為大家詳細(xì)介紹了.NET微信公眾號(hào)獲取OpenID和用戶(hù)信息的方法,用戶(hù)OpenID對(duì)于微信公眾平臺(tái)開(kāi)發(fā)尤為重要,感興趣的小伙伴們可以參考一下2016-11-11.NET Windows 多線(xiàn)程thread編程
.net里使用線(xiàn)程,用thread類(lèi),定義線(xiàn)程,啟動(dòng),銷(xiāo)毀,全部包括在這個(gè)類(lèi)里,定義一個(gè)線(xiàn)程,必須指定這個(gè)線(xiàn)程的函數(shù),也就是這個(gè)線(xiàn)程是做什么的2012-12-12在asp.net中操作sql server數(shù)據(jù)庫(kù)的一些小技巧
在asp.net中操作sql server數(shù)據(jù)庫(kù)的一些小技巧...2006-09-09.net6?在中標(biāo)麒麟下的安裝和部署過(guò)程
這篇文章主要介紹了.net6?在中標(biāo)麒麟下的安裝部署,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04asp.net 獲取目錄下的文件數(shù)和文件夾數(shù)
遍歷一個(gè)文件夾中的文件,需要用到DirectoryInfo類(lèi)中的一個(gè)重要的方法GetFileSystemInfos(),此方法返回指定的是與搜索條件相匹配的文件和子目錄的強(qiáng)類(lèi)型 FileSystemInfo對(duì)象的數(shù)組。2010-07-07