This project is read-only.

Form post problem in sidebar

Apr 23, 2009 at 4:12 PM
I've edited the standard theme to my requirements and have hard coded an html form into the sidebar in the site.master file.

It's a standard form that posts to a page on my main website. When I click the post button nothing happens.

I have the blog system setup as a sub folder "blog" on my domain and have it in it's own app pool etc in IIS.

How can I get the form to post properly? It looks like something happens but it just stays on the page.
Apr 23, 2009 at 8:07 PM
Apr 23, 2009 at 8:12 PM
Is the <form> you added nested within the existing <form>?  Nested forms can cause problems, and aren't technically legal which could be causing the problem.  If you do a View Source in your browser, you can check to see if it's nested or not.  Nested would look like:


That's not allowed.  But multiple un-nested forms are okay:

Apr 23, 2009 at 8:14 PM
Yes it's nested inside the main form. Sorry, I'm a classic ASP person, not .Net. What is the main <form runat="Server" class="body"> form for and do I need it in the template?
Apr 23, 2009 at 8:24 PM
Only in very rare cases can you get away with not having the <form runat="server"> tag.  ASP.NET uses it for a lot of things.

Two possible solutions come to mind.  One is to use an <iframe> with a SRC pointing to a separate HTML document that contains your form.  Another option depending on how your page is laid out is to re-arrange the page contents a bit and use a second contentplaceholder ... I recently wrote a blog post on this.
Apr 23, 2009 at 8:33 PM
No worries, I just moved the main form closing tag, now they're not nested.

Thanks for that
Apr 23, 2009 at 8:36 PM
Whats the .Net equivalent to the following please?

      <%if request.querystring("newsletter") <> "" then%>
      <%end if%>

Apr 23, 2009 at 8:44 PM
In .NET, you can use the same syntax.  Some parts of BE are using that <% ... %> syntax already.

Traditionally, with ASP.NET, you would have a control that you can turn Off or On its visibility depending on whether you want the markup to be outputted.  But the <%  %> tags should work too.
Apr 23, 2009 at 8:47 PM
Thats what I thought but when I put that in my template I get a runtime error
Apr 23, 2009 at 8:57 PM
What's the error message?

You can go the more traditional ASP.NET route.  Depending on what you want to output in the page, the control you need may vary, but a "PlaceHolder" control works in most cases.

<asp:PlaceHolder ID="phNewsletter" runat="server">
   .... your stuff ....

Then in a codebehind file, you would toggle the visibility of the phNewsletter control.  If you are putting this control into the site.master file, in the site.master.cs file (the codebehind file for site.master), you can add code like the following into the Page_Load event handler:

protected void Page_Load(object sender, EventArgs e)
   phNewsletter.Visible = !string.IsNullOrEmpty(Request.QueryString["newsletter"]);
Apr 23, 2009 at 9:18 PM
I just get the runtime error. No specific message.

I've tried your other suggestion and get the same error
Apr 23, 2009 at 9:43 PM
In the Web.config file in the root of your blog, there's a <customErrors> tag:

<customErrors mode="RemoteOnly" defaultRedirect="~/error404.aspx">

Try changing that to the following to see if you get any extra error information.

<customErrors mode="Off">

If not, *any* additional information on what you're seeing could be helpful.
Apr 24, 2009 at 9:02 AM
Compiler Error Message: CS1003: Syntax error, '(' expected

Source Error:

Line 37:
Line 38:     <div id="sidepanel">
Line 39:     <%if request.querystring("newsletter") <> "" then%>
Line 40:     
Line 41:     <%end if%>
Apr 24, 2009 at 1:26 PM
Any ideas on this one?
Apr 24, 2009 at 8:29 PM
The site.master file is using C#, so the code within <% ... %> needs to be C#.  This should work:

<% if (!string.IsNullOrEmpty(Request.QueryString["newsletter"])) { %>
   ... Your content when the newsletter querystring parameter is present ...
<% } %>
Apr 24, 2009 at 8:42 PM
Thanks for that. Works a treat!