[CLOSED] How to hide HtmlEditor's toolbar on server side (C#)

  1. #1

    [CLOSED] How to hide HtmlEditor's toolbar on server side (C#)

    Hello,

    I'm trying to hide HtmlEditor's toolbar on server side (on C# code), but I only found examples doing that on client side. I need to run that on server side

    The code I found for client side is like follows:
    <ext:HtmlEditor ID="myHtmlEditor" runat="server">
        <Listeners>
            <Show Handler="this.getToolbar().hide();"></Show>
        </Listeners>
    </ext:HtmlEditor>
    Are there any "getToolbar" I can use on server side?
    Last edited by fabricio.murta; May 18, 2017 at 10:02 PM.
  2. #2
    Hello @banrisulssw!

    The problem about get methods in code behind is that, specially when they return something, we can't -- during code behind execution -- infer the state of the component. So get methods don't make much sense in code behind, generally speaking.

    That said, usually when you need to interact with components at client side, and if you need that from code behind, you but call the script to do so when when the code behind call finishes.

    It would be something like this, in your case:

    X.AddScript("App.myHtmlEditor.getToolbar().hide()");
    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello, @fabricio.murta!

    I understand and that works fine to me, with a little modification.
    X.AddScript("#{myHtmlEditor}.getToolbar().show();");
    I'll figure out a way to remove this "magical string" from my code, but for now this is the solution for my problem.
    I appreciate your quick reply to our threads. Good job!
    Thanks a lot.
  4. #4
    Hello @banrisulssw!

    Alright, thanks for the feedback! But beware using #{myHtmlEditor} expansion in some situations might not work. This is expanded to Namespace.myHtmlEditor in the end, being the Namespace by default App.

    These tags are expanded on webforms rendering and probably won't work if you return code containing them after the page was rendered. So, in any case you see that the #{myHtmlEditor} (or tags alike) don't work, switch to App.myHtmlEditor.
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hello @fabricio.murta!

    Sure, I don't know what I was doing different... Now I changed the code to "App.myHtmlEditor..." and worked correctly.

    One more question about this:
    I have a scenario where the most people will see myHtmlEditor on readOnly (and toolbar hidden) and when an administrator access the page, he must be able to edit (readonly = false) and some buttons should appear. I can do all of this, but when a regular user open the page, first the toolbar is visible and in a fraction of second it is hidden. That is not a big problem and I know it occurs because this validation occurs on server side. There's any way to set this property to, by default, create the htmlEditor with toolbar hidden? This in particular can be made anywhere on code (aspx or codebehind).
    I already tried to set a listener as the code below and it seems to be in conflict with my DirectEvents...

    <Listeners>
        <BeforeShow Handler="App.myHtmlEditor.getToolbar().hide();" />
    </Listeners>
    <DirectEvents>
        <BeforeShow OnEvent="winEdit_BeforeShow" />
        <Hide OnEvent="winEdit_Hide" />
    </DirectEvents>
    The .cs part:

    protected void winEdit_Hide(object sender, DirectEventArgs e)
    {
        storeAsks.Reload();
        txtUser.Clear();
        myHtmlEditor.Clear();
        txtAnswer.Clear();
    }
    
    protected void winEdit_BeforeShow(object sender, DirectEventArgs e)
    {
        if ( isAdmin())
        {
            btSaveEdit.Hidden = false;
            myHtmlEditor.ReadOnly = false;
            btRemoveFaq.Hidden = false;
    
            X.AddScript("App.myHtmlEditor.getToolbar().show();");
        }
        else
        {
            btSaveEdit.Hidden = true;
            myHtmlEditor.ReadOnly = true;
            btRemoveFaq.Hidden = true;
            X.AddScript("App.myHtmlEditor.getToolbar().hide();");
        }
    
    }
    Edit: This method "isAdmin" is the reason I can't use aspx to hide or show myHtmlEditor's toolbar.

    Thanks a lot for the reply.

    Bruno Crivelatti
    Banrisul SSW
    Last edited by banrisulssw; May 17, 2017 at 6:20 PM. Reason: Forgot to explain "isAdmin" method
  6. #6
    Hello again Bruno!

    What you can do is get an even earlier event to hide/show your toolbar.

    You can also build the HTMLEditor from code behind during page load, guaranteeing you are only emitting the component in the shape the end user need to see then it gets available client-side.

    Anyway, hiding the HTMLEditor's toolbar without overrides would require calling the toolbar's hide() method. I suppose the BeforeRender event happens at a good time to prevent visual glitches/flickers on load:

    <Listeners>
        <BeforeRender Handler="item.getToolbar().hide();" />
    </Listeners>
    For example, if you had a simple component like this: <ext:HtmlEditor runat="server" ID="he1" />

    The below code run on Page_Load will be hiding the toolbar when the HtmlEditor has its toolbar "done" but before it's been rendered to screen. So no missing artifacts when/if a direct event/method calls the toolbar to be displayed.

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!X.IsAjaxRequest)
        {
            var admin = false;
            if (admin)
            {
                he1.Listeners.BeforeRender.Handler = "item.getToolbar().hide();";
            }
                
        }
    }
    But I'm afraid this is as far as I can go without an actual test case from you. If the information above is still confuse, I believe we'd better off with a full test case to better illustrate your scenario and we can talk about the same thing in the algorythm.

    Anyway, hope this helps!
    Fabrício Murta
    Developer & Support Expert
  7. #7
    Good morning, @fabricio.murta!

    Well, your solution is what I need. Thanks for the reply!

    Bruno Crivelatti
    Banrisul SSW
  8. #8
    Glad it helped, Bruno! Thanks for the feedback!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] Disable , hide , and show a tree node from the server side
    By elbanna23 in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 29, 2014, 5:49 AM
  2. Replies: 1
    Last Post: Aug 23, 2012, 7:07 AM
  3. [CLOSED] Hide HtmlEditor Toolbar
    By ndotis in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 23, 2011, 5:39 PM
  4. HtmlEditor Auto-Hide Toolbar
    By koss in forum 1.x Help
    Replies: 0
    Last Post: Feb 23, 2010, 11:31 AM
  5. [CLOSED] Show-Hide BorderLayoutRegion server side
    By methode in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 21, 2009, 9:42 AM

Tags for this Thread

Posting Permissions