Copied to clipboard

Flag this post as spam?

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


  • Adrian Alexa 50 posts 100 karma points
    Jan 11, 2012 @ 14:40
    Adrian Alexa
    0

    Usercontrolers does not work when insert form tag

    Hi,

    I found the same issue on this post( http://our.umbraco.org/forum/using/ui-questions/19391-Usercontrol-not-working-in-umbraco?p=0#comment102880 )

    I will come with details. I create a macro which contains a form 2 hidden fields and a button.

    It renders content on frontend when controller is without form tag. When I insert it it shows me on content tab: No macro content available for wysiwyg editing.

    Here is CODE

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SignUpButton.ascx.cs" Inherits="HoteloProModules.SignUpButton.SignUpButton" %>

    <div class="div_center">
        <form name="formSignUpp" id="formSignUp" runat="server" action="" method="post">
            <div class="btn_class_a">
                <div class="btn_left"></div>
                <asp:HiddenField ID="hidMaxNrOfRooms" Value=""  runat="server"/>
                <asp:HiddenField ID="hidAccountType" Value="" runat="server"/>
                <asp:Button CssClass="btn_center" Text="SIGN TEMP" runat="server" ID="btnSignUp"/>
                <div class="btn_right"></div>
            </div>
        </form>
    </div>

     

    and code behind CODE

     


        public partial class SignUpButton : System.Web.UI.UserControl
        {
            private Int16 MaxNrOfRooms, AccountType;

            /// <summary>
            /// 5, 25, 50
            /// </summary>
            public Int16 _MaxNrOfRooms
            {
                get { return MaxNrOfRooms; }
                set { MaxNrOfRooms = value; }
            }
            /// <summary>
            /// 1 2 or 3
            /// </summary>
            public Int16 _AccountType
            {
                get { return AccountType; }
                set { AccountType = value; }
            }
            protected void Page_Load(object sender, EventArgs e)
            {
                btnSignUp.Text= umbraco.library.GetDictionaryItem("SignUp").ToUpper();
                hidMaxNrOfRooms.Value = _MaxNrOfRooms.ToString();
                hidAccountType.Value = _AccountType.ToString();
                //
                formSignUp.Action = "https://" + HoteloProGenerals.WebAppRootNoScheme + "Register.aspx";
            }
        }

     

    The reason why I need there a form is because I want a button that when is pressed to send/redirect/post to an address transfering values.

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jan 11, 2012 @ 15:38
    Michael Latouche
    0

    Hi Adrian,

    The problem is that your template, if it is a classic asp.net masterpage, probably also contains a global "form" tag. What you could do is remove the form tag from your control, but then change the action of your main form when you click on your formSignUp button.

    So, instead of server-side assigning the form action do it client-side, something like this:

    <input type="submit" id="btnSignUp" onclick="SetSignupAction();">

    and then define a javascript method:

    function SetSignupAction()
    {

    document.forms[0].action = "https://<%HoteloProGenerals.WebAppRootNoScheme%>Register.aspx";

    }

    Or any jquery equivalent...

    Not tested so no error-proff guarantee ;-)

    Hope this helps.

    Cheers,

    Michael.

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jan 11, 2012 @ 15:41
    Michael Latouche
    0

    Sorry, I did not pay attention you were using asp:Net button, so no <input type="submit" .../> for you but

    <asp:Button CssClass="btn_center" OnClientClick="SetSignupAction();" Text="SIGN TEMP" runat="server" ID="btnSignUp" />

    Cheers,

    Michael.

  • Adrian Alexa 50 posts 100 karma points
    Jan 12, 2012 @ 10:05
    Adrian Alexa
    0

    Hi Michael,

    afterall I found a cause why it was like that.

    The macro was inserting in a form that has runat="server". So you can not have one form within other with runat=server.

    The solution: instead of using asp.net cotrollers I used classic html form tags. And it works.

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jan 12, 2012 @ 10:10
    Michael Latouche
    0

    Hi Adrian,

    It's great you found it!

    Cheers,

    Michael.

  • Adrian Alexa 50 posts 100 karma points
    Jan 12, 2012 @ 10:12
    Adrian Alexa
    0

    oh yeah..after some good hours...now I am struggling with language :D (one domain and multiple langs)

Please Sign in or register to post replies

Write your reply to:

Draft