473,395 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 2974
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

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

Similar topics

1
by: KK | last post by:
Windows Forms Inheritance, Incomplete? I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can be used effectively if the...
2
by: KK | last post by:
** Posting it here cause after couple of days no body responded.** I was playing around with Windows Forms and found out this Forms Inheritance feature. The moment I saw that, I felt this can...
0
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
12
by: Peter Van Wilrijk | last post by:
Hi, In VB6 I have the following code ... Dim frmLink As Form Set frmLink = Forms.Add(stringformname) frmLink.Show 'wait until all data has been loaded Do Until frmLink.Loaded = 21 DoEvent
18
by: Jerry Boone | last post by:
I'm looking for a way to fire a public sub/function when a form is opened and closed - without using form level events. I have already done some extensive form work with instancing, looping...
14
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought...
19
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
21
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.