RenderControl throws an error

Last post 10-30-2006, 6:06 PM by kev mc. 8 replies.
Sort Posts: Previous Next
  •  01-07-2005, 11:43 AM 3324

    RenderControl throws an error

    Hi

    I just downloaded the CuteEditor and I'm testing it and it looks very promising.

    I'm trying to render the control on my website instead of using the regular tag. The code I have is this.

    Editor e = new Editor();
    e.Text = "abc";

    StringBuilder sb    = new StringBuilder();
    StringWriter sw        = new StringWriter(sb);;
    HtmlTextWriter htw  = new HtmlTextWriter(sw);;

    e.RenderControl(htw);
    Response.Write(sb.ToString());


    And the error it throws is this
    [NullReferenceException: Object reference not set to an instance of an object.]
    CuteEditor.a.d(HtmlTextWriter A_0) +1247
    CuteEditor.a.f(HtmlTextWriter A_0) +505
    CuteEditor.a.g(HtmlTextWriter A_0) +109
    CuteEditor.a.i(HtmlTextWriter A_0) +57
    CuteEditor.Editor.Render(HtmlTextWriter writer) +43
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    ASP.temp_aspx.__Render__control1(HtmlTextWriter __output, Control parameterContainer) in C:\Projects\trunk\AppServer\web\barn\create\temp.aspx:19
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +27
    System.Web.UI.Control.Render(HtmlTextWriter writer) +7
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
    System.Web.UI.Page.ProcessRequestMain() +1926
    I think I'm doing everything right, but please correct me if I'm wrong.

    Thanks
    ingig


  •  01-07-2005, 1:28 PM 3325 in reply to 3324

    Re: RenderControl throws an error

    ingig,
     
    Can you post your whole aspx page and code-behind page?
     
  •  01-08-2005, 10:03 PM 3341 in reply to 3324

    Re: RenderControl throws an error

    ingig :
     
        The editor can't work correctly if it haven't be added into the page .
     
    Regards , Terry .
  •  01-10-2005, 1:33 PM 3358 in reply to 3324

    Re: RenderControl throws an error

    This is the hole page, I'm not using code-behind(there is a reason why I can't use code-behind)

    <%@ Page Language="C#" %>

    <%@ Import namespace="System.Data" %>
    <%@ Import namespace="System.IO" %>
    <%@ Import namespace="CuteEditor" %>

    <%
        Editor e = new Editor();
        e.Text = "abc";

        StringBuilder sb    = new StringBuilder();
        StringWriter sw        = new StringWriter(sb);;
        HtmlTextWriter htw  = new HtmlTextWriter(sw);;

        e.RenderControl(htw);
        Response.Write(sb.ToString());
    %>

    I'm using this same code for other controls that I include on my website and they work ok, except in those instances they are UserControl not WebControls like CuteEditor. So basically I want to render the control using c# code not using (html like) tag.



  •  01-10-2005, 3:35 PM 3359 in reply to 3358

    Re: RenderControl throws an error


    Put the following code on the top of your page:


    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
     
    You need to add the CuteEditor instance somewhere in your page as well: 
    <CE:Editor id="Editor1" runat="server" ></CE:Editor>

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  01-10-2005, 4:08 PM 3363 in reply to 3359

    Re: RenderControl throws an error

    Hi Adam

    Thanks for your reply

    The thing is I don't want to use <CE:Editor id="Editor1" runat="server" ></CE:Editor> in my code. When  <CE:Editor..... /> is used I need to use <script runat="server"> and the Page_Load(object sender, System.EventArgs e) method or code-behind. This is something that I don't want to do(actually can't do it for a specific boring reason that I don't want get into ).

    Try running this example code on an aspx page
    <%@ Page Language="C#" %>

    <%@ Import namespace="System.IO" %>

    <%
        System.Web.UI.WebControls.Button b = new System.Web.UI.WebControls.Button();
        b.Text = "hello";

        StringBuilder sb    = new StringBuilder();
        StringWriter sw        = new StringWriter(sb);
        HtmlTextWriter htw  = new HtmlTextWriter(sw);

        b.RenderControl(htw);
        Response.Write(sb.ToString());
    %>

    As you can see the result is <input type="submit" name value="hello" /> from that code. That is what I would like from CuteEditor when I call RenderControl. In theory this should work as you can see with the Button WebControl (or any other WebControl that you would try, even non-Microsoft).

    It's like I need initiate some variable sine an "Object reference not set to an instance of an object" exception is thrown.

    Hope you can give me some tip on this

    ingig


  •  11-23-2005, 11:43 AM 12927 in reply to 3363

    Re: RenderControl throws an error

     
    ingig,
     
    Did you ever get a solution to this? I am doing something similar, where I want to hide one Editor and show another using a callback, but in order to do that I need to render the control to an htmlwriter, but get the same error:
     
    exception.ToString() "System.Web.HttpUnhandledException: Exception of type System.Web.HttpUnhandledException was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at CuteEditor.a.a(ContextMenuEnable A_0, String A_1)
    at CuteEditor.a.e(HtmlTextWriter A_0)
    at CuteEditor.a.j(HtmlTextWriter A_0)
    at CuteEditor.a.i(HtmlTextWriter A_0)
    at CuteEditor.a.k(HtmlTextWriter A_0)
    at CuteEditor.Editor.Render(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    .........
     
    Any help anyone could give me would be great.
     
    Cheers,
     
    Tom.
     
    UPDATE: I just found a solution to this problem - the Editor needs to be added to the controls collection of the parent control again (whether it be a UserControl, Page, or in my case a PlaceHolder), even though the actual control itself wasn't null on the Callback. I imagine that one of the internal controls is being nullified at some point, and it would be obvious if all of the runtime code wasn't obfuscated. Hey ho. Hope this helps some people. Great control - best of breed as far as I can tell. Cheers CuteSoft (you should get together with ComponentArt - you could make some awesome controls!!!)
     
  •  10-16-2006, 9:08 AM 23600 in reply to 12927

    Re: RenderControl throws an error

    I'm rendering CuteEditor the same way but I have only regular textarea field instead of a WISIWYG editor. Please advise.
  •  10-30-2006, 6:06 PM 23905 in reply to 12927

    Re: RenderControl throws an error

    I'm still having problems with this - I also need to render the editor to an htmlwriter (for adding to an XML file to be displayed via XSLT)  but when I do it does not seem to initialise properly - the javascript is incomplete, giving me a CuteEditorClientClass is undefined error in the page (in IE)
     
    In IE the editor appears but without about half of it's buttons, in firefox all of the buttons appear but some of the functions are undefined.
     
    I'm guessing that I need to set the browser information somewhere so that the control knows which javascript to write, or I need to make it initialise in some way - any ideas?
     
    The code that I am using looks like this:

    void Page_Load(object sender, System.EventArgs e){

     

       StringBuilder ceBuilder = new StringBuilder();
       StringWriter ceStringWriter = new StringWriter(ceBuilder);
       
    HtmlTextWriter ceTextWriter = new HtmlTextWriter(ceStringWriter);
       
    PlaceHolder ceHolder = new PlaceHolder();
        ceHolder.Page = this
       CuteEditor.
    Editor ce = new CuteEditor.Editor(); 
       ce.ID =
    "editor1"
       ce.EditorWysiwygModeCss =
    "/editor/example.css";
       
    int tc = ce.ToolControls.Count; //without this line the RenderControl method falls over (undefined object)
       ce.Text =
    "hi";
       ceHolder.Controls.Add(ce);
       ceHolder.RenderControl(ceTextWriter);
       Response.Write(ceBuilder.ToString());
    }
View as RSS news feed in XML