0
votes

I learned that in umbraco, we have to use a master template for a custom user control. I have a custom form and a submit button. I created a control that sends an email once the 'submit" button is pressed. the control basically gets all the fields like name, address. It works when I create a new template and insert the macro.

However when I try to use it with a master template, it does not work. The submit button refreshes the page but never goes to my c# part where it sends the mail

and if I do this

     <form name="myform" target="_self" method="post" action="index">

it goes to the index page, but no email is sent.

But it works on a clean or new template. Is there a way to use custom control with master template in umbraco 4 EDIT - This is how I am using macro

<form name="myform" target="_self" method="post" action="index">    
   <umbraco:Macro Alias="sendMail" runat="server"></umbraco:Macro>
</form>
2
What do you mean, a custom controller? Are you using MVC in Umbraco 4, and if so, how? - Evan Harper
I just create a new project in VS2010, and then create a web user control and use that controller in umbraco - EagleFox
A control is not the same thing as a controller. Be careful to use exact language or you will find it difficult to get help. - Evan Harper
Thanks Evan... I will edit my posts - EagleFox

2 Answers

1
votes

Looking at the code it looks like you are missing the runat="server" attribute on the form tag.

<form name="myform" runat="server">    
   <umbraco:Macro Alias="sendMail" runat="server"></umbraco:Macro>
</form>

By using the runat=server attribute the form tag will be rendered with the correct attributes. Note you can only have one runat="server" form on a page.

There's some more information on this concept on W3Schools

1
votes

I assume you are using ASP.NET WebForms. I have Umbraco sites in which I also use a Master Template and a Macro which contains a form. This should work normally. What I notice is that you have set the "action" attribute which is ignored. Also the "method" attribute default value is "post" so you don't need to set both these properties.

An ASP.NET Webform is always posting to itself, so you can remove the "target" property here. I'm not sure that removing these "unwanted" attributes will solve your problem.

If not, are you using nested .NET Forms? That is throwing errors and strange behavior as well.