Copied to clipboard

Flag this post as spam?

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


  • Enrique Gutierrez 7 posts 29 karma points
    Nov 30, 2009 @ 22:24
    Enrique Gutierrez
    2

    Multiple Form Problem

    This situation seems to be all over the place & I'm seeing mixed results for various code configurations in this forum and a lot of others, so I decided to post a topic for my specific scenario to see what the possible solutions might be:

    1. I'm using the Runway DropdownNavigation control

    2. I'm using Umbraco Contour

    3. I also have a search form that needs to post to /search.aspx (from XSLT Search)

    If I put a form runat=server tag around the master page, the DropdownNavigation control and the Umbraco Contour Form function fine, but the Search Form doesn't do anything because it is posting back to the page hosting the forms (/default.aspx for example). If I try to put individual form runat=server tags around the DropdownNav and the container that holds Contour, I get the "you can only have one server side form per page" error that seems to plague plenty of other folks.

    If I try to alter the search form to be an ASP.NET controlled form in efforts to get PostBackUrl to submit my text box to /search.aspx - like so:

                <div id="searchbarbox">
                        <asp:TextBox ID="search" CssClass="input" Text="" runat="server"></asp:TextBox>
                        <asp:Button ID="submitSearch" PostBackUrl="/search.aspx" runat="server" Text="Search" CssClass="submit" />
                </div>

    It simply doesn't do anything, and also renders the Umbraco Contour form useless; while the DropdownNavigation control still works fine... 

    Insights?

     

     

  • Petr Snobelt 923 posts 1535 karma points
    Dec 01, 2009 @ 08:28
    Petr Snobelt
    0

    You can catch submitSearch onclick event and simply do response.redirect to url for search similar to this

    Response.Redirect("/search.aspx?search=" + search.Text);

     

    Petr

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Dec 01, 2009 @ 08:52
    Scott Hugh Alexandar Petersen
    1

    Yep that does seem like a common problem, however look what I did and it really works like a charm!

    <%@ Master Language="C#" MasterPageFile="/umbraco/masterpages/default.master" AutoEventWireup="true" %>



    <!-- content place holder from the default master page from Umbraco -->
    <asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
     <title>Title :)</title>
    </head>
    <body>
    <!-- outer container -->
    <div id="outer">
    <!-- top container -->
    <div id="top">&nbsp;</div>
    <!-- mid container containing 2 forms, one .net and one regular html -->
     <div id="mid">
    <!-- .net form -->
      <form id="frm" runat="server">
    <!-- content container -->
    <div class="content">
      <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
        <asp:ContentPlaceHolder ID="cphContent" runat="server"></asp:ContentPlaceHolder>
    </div>
      </form>
    <!-- search box with html form (should be outside the .net form tag) -->
      <div class="search">
        <!-- the search will automatically post when you hit enter! -->
    <!-- postbackurl /search.aspx (whatever you want it to be) -->
        <form action="/search.aspx" method="post">
         <input type="text" id="search" name="search" />
         <input type="submit" id="submitSearch" name="submitSearch" value="Search" />
        </form>
      </div>
     </div>
    <!-- bottom container -->
    <div id="Bottom">
    &nbsp;
    </div>
    </div>
    </body>
    </html>
    </asp:Content>

    Actually it is all in the css because as the search box is not important for the user or the developer to be .net (at least for now) well then it does not need to be included in a .net form (which means that it does not need an runat="server" attribute).

    As you can put your search box where ever you want to with css and just accommodate the other elements on your page to fit your needs then it does not have to be inside a .net form tag - which makes the solution much more solid.

    Two forms, now clashes between nothing at all. If you have any probs feel free to ask...

    Just remember at all times that the search box can be placed wherever you want it to be placed with css. I do it all the time and it is so easy if you understand this concept.

    Scott

  • Enrique Gutierrez 7 posts 29 karma points
    Dec 01, 2009 @ 09:57
    Enrique Gutierrez
    0

    Petr -

    I added:

    <script Language="c#" runat="server">
      public void doClick (object sender, EventArgs e)
      {
        Response.Redirect("/search.aspx?" + searchBox.Text);
      }
    </script>

    And have

    <div id="searchbarbox">
            <asp:TextBox ID="searchBox" CssClass="input" Text="" runat="server"></asp:TextBox>
            <asp:Button ID="submitSearch" OnClick="doClick" runat="server" Text="Search" CssClass="submit" />
    </div>

    But; it's not doing anything. It's a shame - I had high hopes.It does, however, trigger the "required fields" in my Umbraco Contour form, and renders it non-functional; same type issue I was having before. Though I'm not a huge fan of butchering forms around ASP.NET via CSS, I may just lean on Scott's work-around until I can find the fix.

    If I remember it - I'll post it.

  • Petr Snobelt 923 posts 1535 karma points
    Dec 01, 2009 @ 10:07
    Petr Snobelt
    0

    Try

    Response.Redirect("/search.aspx?search=" + searchBox.Text);
  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Dec 01, 2009 @ 10:50
    Scott Hugh Alexandar Petersen
    0

    Hey Enrique,

    I think that the solutiong I provided before is the most solid and it works flawless, there are other solutions around which puts and empty

    <style type="text/css">
    .Hidden
    {
    display: none;
    }
    </style>

    <asp:TextBox id="txtEmpty" runat="server" cssclass="Hidden" />

    However it did not work for me, and the other solution provided has been working very good and it does excactly what I want it to do.

    Scott

  • Petr Snobelt 923 posts 1535 karma points
    Dec 01, 2009 @ 11:22
    Petr Snobelt
    0

    When it's possible use solution which Scott describe: another form without runat="server" outside main form. But it isn't always an option (when you want use canvas for example), then use redirect solution.

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Dec 01, 2009 @ 11:47
    Scott Hugh Alexandar Petersen
    0

    Petr, can you dig a little deeper into why it won't work with canvas? (I honestly haven't tested it myself with canvas).

    Scott

  • Petr Snobelt 923 posts 1535 karma points
    Dec 01, 2009 @ 13:56
    Petr Snobelt
    0

    @Scott: Sorry for inaccuracy, multiple forms solution works fine with canvas, but controls which can be editable using canvas should be in runat server form, and implemented design sometimes do not allow to have search outside of main form.

  • Scott Hugh Alexandar Petersen 349 posts 164 karma points
    Dec 01, 2009 @ 15:29
    Scott Hugh Alexandar Petersen
    0

    @Petr: Ah okay, now I understand, thank you for clearing that up.

  • John Perryn 71 posts 182 karma points
    Nov 09, 2012 @ 06:05
    John Perryn
    0

    The ASP.NET <form runat="server" /> concept is Very Confusing and I'm sue that it leads to much wasted time. It certainly has for me as a newcomer to ASP.NET who has just wasted 2+days and still not happy.

    @scott Thank you for this "workaround" which has moved my project forwards, although I am internally convinced that there must be a better solution. What would a professional ASP.NET programmer do? Meanwhile...
    RE:"..Just remember at all times that the search box can be placed wherever you want it to be placed with css. I do it all the time and it is so easy if you understand this concept..."

    I have been unable to find a combination of CSS that works to reposition the search form to be stable at the top of my page such that it repositions correctly when the page is resized. I'm currently using:

    #search_form {
        position: absolute;
        top: 3px;
        left: 940px;
    }

    Suggestions welcome!

    John P

Please Sign in or register to post replies

Write your reply to:

Draft