Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dima Vyprichenko 1 post 21 karma points
    Feb 03, 2013 @ 21:17
    Dima Vyprichenko
    0

    Using Umbraco API in code behind causes PageRequestManagerServerErrorException

    Hi.

    This is the situation: I'm creating an Ajax comment form for my site. At first I solve it with writing a BaseExtension class, that processed post request from the page, and that worked. But then I've decided to add AST.NET Captcha module. So, I've edited my form, added a code-behind file with event handler for submit action. Handler calls function, that verifies the captcha-input field value and, if true, have to create new Document under certain node.

    Form:

            <form id="reviewForm" class="reviewForm" runat="server">
                <asp:ScriptManager ID="ScriptManager" runat="server"/>
                <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="submit" />
                    </Triggers>
                    <ContentTemplate>
                        <fieldset>
                        <h2> </h2>
                
                        <label>
                            <span> :</span>
                            <input value="" name="name"/>
                        </label>
                        <label>
                            <span>E-mail:</span>
                            <input value="" name="email"/>
                        </label>
                        <label>
                            <span>:</span>
                            <textarea name="comment"></textarea>
                        </label>
                        </fieldset>
                        <fieldset>
                        <label>
                            <span> :</span>
                            <input autocomplete="off" id="CaptchaInput" name="captcha" maxlength="5" runat="server"/>
                        </label>
                        <cc1:CaptchaControl ID="CaptchaCode" runat="server"
                            CaptchaBackgroundNoise="Low" CaptchaLength="5"
                            CaptchaHeight="40" CaptchaWidth="120"
                            CaptchaLineNoise="None" CaptchaMinTimeout="5"
                            CaptchaMaxTimeout="240" FontColor = "#4e5da1" />
                        </fieldset>
                                           
                      <button id="submit" type="button" runat="server"></button>
                      
                    </ContentTemplate>
                </asp:UpdatePanel>
            </form>

    Code behind fragment:

    ...
    using umbraco;
    using umbraco.webservices;
    using umbraco.cms.businesslogic.web;
    using umbraco.presentation.nodeFactory;
    namespace CommentForm
    {
        public partial class Itemmaster : System.Web.UI.MasterPage
        {
            ...
            protected void Submit_Clicked(object sender, EventArgs e)
            {
                System.Threading.Thread thread = new System.Threading.Thread(() =>
                {
                    CaptchaCode.ValidateCaptcha(CaptchaInput.Value);
                    if (CaptchaCode.UserValidated)
                    {
                        CaptchaInput.Value = "RIGHT!"; // -- works;
                        Node root = new Node(-1); // -- fails!;
                    }
                    else
                    {
                        CaptchaInput.Value = "WRONG!";
                    }
                });
                thread.SetApartmentState(System.Threading.ApartmentState.STA);
                thread.Start();
            } 
    ...
        }
    }

    Umbraco 4.5.2, .NET 3.5

    All this works partially: the Captcha verifies without problems and I can, for example, place text "Success" or "Error" back to page. But since I need to create new Document, I try to get current node's Id. And when I add any code, that uses Umbraco API, I receive:

    Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 0 

    I'm new to .NET and I hope for your help. Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft