FreeTextBox

The no. 1 free ASP.NET HTML Editor.
Welcome to FreeTextBox Sign in | Join | Help
in Search

FreeTextBox with ASP.NET Ajax solution

Last post 05-25-2008, 11:53 PM by ctlatd2. 20 replies.
Page 1 of 2 (21 items)   1 2 Next >
Sort Posts: Previous Next
  •  03-01-2007, 7:59 AM 7984

    FreeTextBox with ASP.NET Ajax solution

    I found a way to make FreeTextBox work in the Edit template of an ASP.NET Ajax updatepanel control. It took me a day or so and it involves some serious hacking. Maybe this method is not completely efficient, but I thought I'd share it with you all and see if there are other ideas.

    The problem with FreeTextBox / updatepanel is, the clientscript does not get registered with the page and the startup script, which runs on page load and initializes the textbox control, is never executed. As I found out, FreeTextBox uses the ASP.NET 1.x clientscript registration functions directly on the ASP.NET Page object. My workaround consists of the following steps:

    1. Register client script manually from code
    2. Override/overload the clientscript registration functions on the page and make them register the startup / the scripts with the ScriptManager control.

    1. Register client script

    The FreeTextBox js includes should be available on the page at all times, so here is the code to register them manually (ASP.NET 2.0 VB). I created a Page class that inherits the Web.UI.Page class and contains the following server script and derived all my pages from this custom Page class. Make sure you copy the js files from the FreeTextBox download package to your website and update the file paths in the script below.

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       If Not IsPostBack Then
          Page.ClientScript.RegisterClientScriptInclude("FTBFreeTextBox", VirtualPathUtility.MakeRelative(Request.Path, "~/ftb/FTB-FreeTextBox.js"))
          Page.ClientScript.RegisterClientScriptInclude(
    "FTBUtility", VirtualPathUtility.MakeRelative(Request.Path, "~/ftb/FTB-Utility.js"))
          Page.ClientScript.RegisterClientScriptInclude(
    "FTBToolbarItems", VirtualPathUtility.MakeRelative(Request.Path, "~/ftb/FTB-ToolbarItems.js"))
          Page.ClientScript.RegisterClientScriptInclude("FTBPro", VirtualPathUtility.MakeRelative(Request.Path, "~/ftb/FTB-Pro.js"))
       End
    If
    End Sub

    2. Override/overload the clientscript registration functions on the page

    The following server code is from the same page class.

    Public Overloads Sub RegisterOnSubmitStatement(ByVal key As String, ByVal script As String)
       ScriptManager.RegisterOnSubmitStatement(Me, GetType(Page), key, script)
    End Sub

    This code makes all ASP.NET 1.x OnSubmit script registrations will be handled by the ScriptManager control. I did not check if the key is a FreeTextBox key, because I have no other controls on the page at this time using these functions. I guess one could do a little debugging and find out the keys FreeTextBox uses, so that only FreeTextBox script are redirected to the ScriptManager.

    The following code is the same for Startup script. However, as FreeTextBox registers it's startup script in the window load event, it still will not work, because the load event is not raised during a partial page update. So, we have to filter the event registration from the script, which is exactly what the two Replace functions are doing.

    Public Overrides Sub RegisterStartupScript(ByVal key As String, ByVal script As String)
       ScriptManager.RegisterStartupScript(
    Me, GetType(Page), key, Replace(Replace(script, "FTB_AddEvent(window,'load',function () {", ""), "});", ""), False)
    End Sub

    As I mentioned before, it's not completely efficient but it's the only way I was able to make it work. I guess the problem would be efficiently solved if FreeTextBox would provide a boolean property (e.g. RegisterWithAjax), and then register with the ScriptManager if RegisterWithAjax is set to true.

    Please let me know other workarounds or improvements on this code!

  •  03-01-2007, 5:37 PM 7987 in reply to 7984

    • senyl is not online. Last active: 22 Mar 2007, 12:17 PM senyl
    • Top 100 Contributor
    • Joined on 02-26-2007
    • Avoiding Mustard gas in the Tooele desert
    • Posts 11

    Re: FreeTextBox with ASP.NET Ajax solution

    You are right.  That IS a serious hack.

    I followed your steps, but I did it in C#.  My situation is different than yours.  I have my FTB in a custom web control that only displays the FTB after partial postback.

    If I change the container to be a Panel instead of an UpdatePanel, and post the full postback, it works fine.  Once I throw in AJAX, it breaks.

    Here is my base page code:

    public class ContentManagementBasePage : System.Web.UI.Page
    {

    protected void Page_Load(object sender, EventArgs e)
    {

    if (!Page.IsPostBack)
    {
    Page.ClientScript.RegisterClientScriptInclude(
    "FTB-FreeTextBox", VirtualPathUtility.MakeRelative(Request.Path, "~/scripts/FTB-FreeTextBox.js"));
    Page.ClientScript.RegisterClientScriptInclude(
    "FTB-Utility", VirtualPathUtility.MakeRelative(Request.Path, "~/scripts/FTB-Utility.js"));
    Page.ClientScript.RegisterClientScriptInclude(
    "FTB-Toolbars", VirtualPathUtility.MakeRelative(Request.Path, "~/scripts/FTB-ToolbarItems.js"));
    Page.ClientScript.RegisterClientScriptInclude(
    "FTB-ImageGallery", VirtualPathUtility.MakeRelative(Request.Path, "~/scripts/FTB-ImageGallery.js"));
    Page.ClientScript.RegisterClientScriptInclude(
    "FTB-Pro", VirtualPathUtility.MakeRelative(Request.Path, "~/scripts/FTB-Pro.js"));
    }
    }

    public new void RegisterOnSubmitStatement(string key, string script)
    {
    ScriptManager.RegisterOnSubmitStatement(this, typeof(Page), key, script);
    }

    [Obsolete]
    public override void RegisterStartupScript(string key, string script)
    {
    string newScript = script.Replace("FTB_AddEvent(window,'load',function () {", "").Replace("});", "");
    ScriptManager.RegisterStartupScript(this, typeof(Page), key, newScript, false);
    }
    }

    And the weird thing is that it doesn't show the borders of the control.  So for me, it half way worked.

    Maybe I have to mod the css refs too.

    I think the next version should work with AJAX out of the box.

  •  03-23-2007, 9:25 AM 8061 in reply to 7984

    Re: FreeTextBox with ASP.NET Ajax solution

    Nander you are my hero!!!!!!!!

    I figured I would spend days trying to work this out, thank you!

    My first born will be named after you...

  •  04-15-2007, 11:46 AM 8133 in reply to 7984

    Re: FreeTextBox with ASP.NET Ajax solution

    I want to thank you for this helpful solution. I tested it in my C# Web Application and it works fine. But I found a problem with pages that use the MultiView and the Wizard controls. I have a WebForm that has two Views, the first has a FTBControl and the second does not. While the page is in the first View (ActiveViewIndex = 0) with the FTBControl everything, including postbacks, works fine. But when you switch the ActiveViewIndex in the MultiView control from 0 to 1 the page becomes instable and does not allow more postbacks. A javascript error "Access denied" is generated when you try to do a postback. I tried to do several tests with the FTB registration scripts but nothing works. Any idea ?

    Thanks anyway !!!

  •  06-06-2007, 5:16 PM 8281 in reply to 7984

    Re: FreeTextBox with ASP.NET Ajax solution

    GENIOUS!!! Thanks Nander! This saved me some much needed time and energy on one of my projects. This beer's for you!
  •  06-22-2007, 9:32 AM 8340 in reply to 7984

    Re: FreeTextBox with ASP.NET Ajax solution

    Works like a charm!

    I can only join he ones before me, bow humbly, and proclaim you are the greatest, Nander ;)

    Thanks a million!

     

  •  06-23-2007, 6:34 AM 8344 in reply to 7984

    Re: FreeTextBox with ASP.NET Ajax solution

    Its works fine for me!

    But when i run IE in debugg mode and trig the OnSaveClick event, and when is leaving the page i got a error.

    The Error seeams to be something with the FTB_RemoveEvent, on the blur event..
    Is it only me that have this error?

  •  09-08-2007, 7:12 AM 8527 in reply to 8344

    Re: FreeTextBox with ASP.NET Ajax solution

    Edstrom:

    Its works fine for me!

    But when i run IE in debugg mode and trig the OnSaveClick event, and when is leaving the page i got a error.

    The Error seeams to be something with the FTB_RemoveEvent, on the blur event..
    Is it only me that have this error?

    Is there any further comments on this item here? Are there any other genious work-arounds?

  •  09-14-2007, 7:46 AM 8538 in reply to 7984

    Re: FreeTextBox with ASP.NET Ajax solution

    I am a Cat meow!...I lost one of my 9 lives...Thank you for saving my 8th Nander!

    I can now update my data from a Formview control..very nice!

  •  10-04-2007, 8:49 PM 8588 in reply to 7987

    Re: FreeTextBox with ASP.NET Ajax solution

    I am also using C#, and I run into exactly same problem.  Textbox loses borders.

    Do you have any work arounds?

     

     

  •  10-13-2007, 9:39 AM 8609 in reply to 8588

    Re: FreeTextBox with ASP.NET Ajax solution

    u know what, u re the maaaaaaaaaaaaaaaaaaaaannnnnnnnnnnnnnnnnnnnnnnnnnnnn

    :)

    thanks to all of guys.

  •  11-30-2007, 3:19 PM 8756 in reply to 7984

    Re: FreeTextBox with ASP.NET Ajax solution

    Is there any fix for this issue in the freetextbox control yet without having to hack one?
  •  11-30-2007, 3:42 PM 8757 in reply to 8344

    Re: FreeTextBox with ASP.NET Ajax solution

    Edstrom:

    Its works fine for me!

    But when i run IE in debugg mode and trig the OnSaveClick event, and when is leaving the page i got a error.

    The Error seeams to be something with the FTB_RemoveEvent, on the blur event..
    Is it only me that have this error?

    I am also getting this error.  I hope that the fix is integrated into the control so that hacking can be removed and errors as these are not presented.

  •  12-17-2007, 2:03 PM 8793 in reply to 7984

    Re: FreeTextBox with ASP.NET Ajax solution

    Nander, Thank you soooo much!

    Just one small problem, how can i take off the js error message at the status bar?

  •  12-19-2007, 6:43 AM 8795 in reply to 7984

    Re: FreeTextBox with ASP.NET Ajax solution

    Nader,

       Can we add any text at the cursor position? How to know if the text in the editor is changed? Thanks in advance.

    Regards

    Maanikala

     

     

Page 1 of 2 (21 items)   1 2 Next >
View as RSS news feed in XML
www.freetextbox.com