Copied to clipboard

Flag this post as spam?

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


  • Bryan Drenner 37 posts 59 karma points
    Feb 24, 2011 @ 23:09
    Bryan Drenner
    0

    SetFocus() not working in macros based on user controls

    This may not be a bug, but I can't find an otherwise appropriate place to post:

    I have created a user control that manifests the contents of a form, and I have placed it in an Umbraco page.  Once published, the registration form behaves correctly, except for one thing:  The SetFocus() calls seem to have no effect, so the cursor does not start in the first TextBox as intended.  However, they do work if I place the user control on a simple, non-Umbraco aspx page.

    Any thoughts?

    Thanks,
    Bryan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 24, 2011 @ 23:11
    Jan Skovgaard
    0

    Hi Bryan

    Do you insert the macro directly on the template or through the content section in a rich text editor?

    And could you perhaps post a snippet of the code in your file?

    /Jan

  • Bryan Drenner 37 posts 59 karma points
    Feb 24, 2011 @ 23:23
    Bryan Drenner
    0

    Thank you for your quick response! The macro is on the template. Here's the code that is not working, excerpted from the user control's code-behind file:

    protected void Page_PreRender(object sender, EventArgs e)
    {
        switch (NewWebAccountWizard.ActiveViewIndex)
        {
            case 0:
                Page.SetFocus(FirstTimeAnswer);
                Page.Form.DefaultButton = FirstTimeNextButton.UniqueID;
                break;
            case 1:
                Page.SetFocus(NewAccountSurnameTextBox);
                Page.Form.DefaultButton = NewAccountNextButton.UniqueID;
                break;
            case 2:
                Page.SetFocus(ConfirmDetailsNextButton);
                Page.Form.DefaultButton = ConfirmDetailsNextButton.UniqueID;
                break;
        }
    }

    Basically, NewWebAccountWizard is a multiview, and depending on which view is active after the user control's logic has executed, it sets the focus and default button right before it's rendered.

  • Bryan Drenner 37 posts 59 karma points
    Feb 28, 2011 @ 17:50
    Bryan Drenner
    0

    I still haven't been able to resolve this issue, but I've found some additional clues.

    When I place the user control on a regular ASPX page, the focus gets set correctly, but in an Umbraco page it no longer works.

    On a regular ASPX page, the following JavaScript reference is automatically generated:

    <script src="/WebResource.axd?d=W5qNQ0304KSxjOdxTSWb-jDDppYWBRdyf4JiCLY6Cor1ICcie99Z5QxrYafHEQH4G3vxRBGr0m5AjfeV7QaI_yYorapuBawuLTdJvK3YVx81&t=634267145163241050" type="text/javascript"></script>

    Along with this, at the bottom of the form:

    WebForm_AutoFocus('ctl02_EmailTextBox');

    But when placed on an Umbraco page as a macro, the same user control omits this code.

    I thought that the problem might be due to the user control being placed in an ASP Content control, so I created a simple master page with a single ContentPlaceHolder, and I placed my user control in the Content control of a child page. It worked there without a hitch.

  • Bryan Drenner 37 posts 59 karma points
    Feb 28, 2011 @ 21:29
    Bryan Drenner
    0

    Solved! After much hair pulling and nail biting.

    My user control had periods in the filename, like this:

    LibraryProject.UserControls.LoginForm.ascx

    When I remove all but the last period...

    LibraryProjectUserControlsLoginForm.ascx

    ...the expected JavaScript is generated on the page, and SetFocus() works as intended.

    Now the question remains for Umbraco developers: Why do extra periods in a user control's filename throw off ASP.NET's built-in JavaScript when used as an Umbraco macro?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies