Hi all
I have javascript function that insert text into freetextbox at current cursor position. It works well when I call this function onClientClick event passing a string as a parameter (This string is inserted into freetextbox at current cursor position). My code is as follow
<FTB:FreeTextBox id="FreeTextBox1" toolbarlayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu,
FontForeColorPicker,FontBackColorsMenu, runat="Server" DesignModeCss="designmode.css" EnableSsl="True" Focus="True"/>
<asp:Button ID="btnInsert" Text="Insert Text" CssClass="button" runat="server" OnClientClick="insertValue('abc');" />
<script language="javascript" type="text/javascript">
function insertValue(field) {
FTB_API['<%=FreeTextBox1.ClientID%>'].Focus();
FTB_API['<%=FreeTextBox1.ClientID%>'].InsertHtml(field);
FTB_API['<%=FreeTextBox1.ClientID%>'].Focus();
window.event.returnValue =false;
}
</script>
The above code is working fine and insert string 'abc' into freetextbox's cursor position
But I want to insert string from code behind file in C#.Net (Server side text)
For this purpose I removed the OnclientClick from btnInsert and passed called this javascript function on page load but it does not work
The New code is given below
//Code Behind
protected void Page_Load(object sender, EventArgs e)
{
string str = "Abc";
btnInsert.Attributes.Add("OnClick", "insertValue('" + str + "')");
}
//HTML Code It is same as above except OnClientClick="insertValue('abc') has been removed.
<FTB:FreeTextBox id="FreeTextBox1" toolbarlayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu,
FontForeColorPicker,FontBackColorsMenu, runat="Server" DesignModeCss="designmode.css" EnableSsl="True" Focus="True"/>
<asp:Button ID="btnInsert" Text="Insert Text" CssClass="button" runat="server" />
<script language="javascript" type="text/javascript">
function insertValue(field) {
FTB_API['<%=FreeTextBox1.ClientID%>'].Focus();
FTB_API['<%=FreeTextBox1.ClientID%>'].InsertHtml(field);
FTB_API['<%=FreeTextBox1.ClientID%>'].Focus();
window.event.returnValue =false;
}
</script>
I am also using AJAX Scriptmanager on my webpage.