471,107 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,107 software developers and data experts.

2 Forms to make 1 form work - ASP.NET

I never had this kind of issue before and it is completely surprising. I have a usercontrol where I need 2 forms to make 1 form. When I have only 1 form it submits the page to itself. I have spent hours on this and couldn't find the solutions, thats why I have to come with a hack. I have two forms, I made the first form invisible and let the second form visible.This form is for google custom search engine. I also tried with other test forms, but still I need to have 2 forms to make 1 form work in this user control. Name of the user control is header.ascx (in case the name got anything to do with this weird issue).

Expand|Select|Wrap|Line Numbers
  1. <span style="visibility:hidden;position:absolute;left:0px;">
  2. <form id="cse-search-box" action="search.aspx" onsubmit="return validateSearch();" visible="false">
  3. <div class="searchSpan">
  4. <input name="cx" type="hidden" value="002116985177671925771:cz5fh8mpenw" />
  5. <input name="cof" type="hidden" value="FORID:11" />
  6. <input name="ie" type="hidden" value="UTF-8" />
  7. <input id="q" name="q" size="22" value="test"/>
  8. <input name="sa" id="searchSubmit" type="submit" value="Search" />
  9. <script src="http://www.google.com/jsapi" type="text/javascript"></script>
  10. <script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script>
  11. <script src="http://www.google.com/coop/cse/t13n?form=cse-search-box&amp;t13n_langs=en" type="text/javascript"></script>
  12. <script src="http://www.google.com/coop/cse/brand?form=cse-search-box&amp;lang=en" type="text/javascript"></script>
  13. </div>
  14. </form></span>
  15.  
  16. <form id="cse-search-box" action="search.aspx" onsubmit="return validateSearch();">
  17. <div class="searchSpan">
  18. <input name="cx" type="hidden" value="002116985177671925771:cz5fh8mpenw" />
  19. <input name="cof" type="hidden" value="FORID:11" />
  20. <input name="ie" type="hidden" value="UTF-8" />
  21. <input id="Text1" name="q" size="22"/>
  22. <input name="sa" id="Submit1" type="submit" value="Search" />
  23. <script src="http://www.google.com/jsapi" type="text/javascript"></script>
  24.  <script type="text/javascript">google.load("elements", "1", { packages: "transliteration" });</script>
  25. <script src="http://www.google.com/coop/cse/t13n?form=cse-search-box&amp;t13n_langs=en" type="text/javascript"></script>
  26. <script src="http://www.google.com/coop/cse/brand?form=cse-search-box&amp;lang=en" type="text/javascript"></script>
  27. </div>
  28. </form>
  29.  
But this kind of issue doesn't happen in another user control where I have different form and it works normally. Anyone had this kind of issue before??
Jun 28 '09 #1
5 2854
Frinavale
9,735 Expert Mod 8TB
I have no idea what you're trying to explain.

Please note that if you set an ASP.NET control's Visible property to False it will not be rendered in the browser...

I have feeling that you are going to want to look into using Web Services with AJAX.NET to make an asynchronous call to the searching service that returns you some results.

I don't know why you would ever need 2 forms.
Never mind that but the <form> tag is meant to be used in the ASPX page, not an ASCX (user control)....

What are your requirements?

I think you're going to need to take a look at the search service that you're using....if you could provide us with a link to the API for this search service it might help us give you a better answer.

-Frinny
Jun 29 '09 #2
Thanks for the answer. Actually the problem was that I have a page that is using different controls and those user controls are within a single form tag. And in the header user control (where the search bar is), I have another form tag, which wasnt working at all, thats why I used that "hack" of two forms to make that search form work. After some research I found out that I cannot have a form tag within another form tag. My main page looks like this

Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <form id="myForm" action="">
  3. <table id="mainTable" align="center" border="0">
  4.     <tbody>
  5.     <tr>
  6.         <td>
  7.         <uc:pageHeader ID="pageHeader" runat="server" />
  8.  
  9.         <uc:topMenu id="topMenu" runat="server" />
  10.         <table id="mainContainer" border="0" cellspacing="0px">
  11.             <tbody>
  12.             <tr>
  13.                 <!-- Left Menu -->
  14.                 <uc:leftMenu ID="leftMenu" runat="server" />
  15.  
  16.                 <td id="mainContainerTextArea" valign="top">
  17.                     <uc:homeText id="homeText" runat="server" />
  18.  
  19.                 </td>
  20.             </tr>
  21.         </tbody>
  22.         </table>
  23.  
  24.         </td>
  25.     </tr>
  26.     <uc:footer ID="footer" runat="server" />
  27. </tbody>
  28. </table>
  29. </form>
  30. </body>
  31. </html>
  32.  
Btw, do I Really need user controls wrapped in form tags. User controls are working fine without being wrapped in form tags as well.
Jun 30 '09 #3
Frinavale
9,735 Expert Mod 8TB
Your user controls should never have <form> tags in them.
User controls are meant to be added to ASPX pages which have a <form> tag...even the ASPX pages might not have a <form> tag in them depending on whether or not you are using MasterPages.


You should only ever have 1 <form></form> tag on the page (whether it be in the ASPX page or in the MasterPage).
Jun 30 '09 #4
@Frinavale
What if I have two different portions of a page and both submit themselves to a different page, then one form tag won't work. Don't I need two form tags then?

Also, whats the reason that we shouldn't have form tag(s) in user controls? Any security or performance risk?

Thanks for the reply :)
Jun 30 '09 #5
Frinavale
9,735 Expert Mod 8TB
@programmerboy
It's possible but it makes things confusing.

There is a way to have elements on one page submit to another... but really why would you need to? If you must do this then your design is probably unnecessarily complicated.

@programmerboy
It has nothing to do with security, nor performance. The reason you should not have a form tag in a user control is because user controls are supposed to be used (as a control) in a page. As I stated earlier, the page that the user control is added to will have the form tag, and (as you've discovered) you cannot have a form tag within a form tag.


Please note that User Controls have a page life cycle that is the same as an ASPX page. So anything submitted to the User Control will seem like it's "submitting to it's own page"....in other words, you implement a User Control the same way that you would implement an ASPX page, but the User Control does not have a form tag. That belongs to the parent page of the User Control.
Jun 30 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by KK | last post: by
reply views Thread by Tim Haughton | last post: by
12 posts views Thread by Peter Van Wilrijk | last post: by
18 posts views Thread by Jerry Boone | last post: by
14 posts views Thread by =?Utf-8?B?UHVjY2E=?= | last post: by
21 posts views Thread by Dan Tallent | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.