473,789 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2 Forms to make 1 form work - ASP.NET

84 New Member
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 2993
Frinavale
9,735 Recognized Expert Moderator Expert
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
programmerboy
84 New Member
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 Recognized Expert Moderator Expert
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
programmerboy
84 New Member
@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 Recognized Expert Moderator Expert
@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
3752
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 application contains couople of forms which have a consistant look and also shares SOME similar functionality between the forms.
2
2203
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 be used effectively if the application contains couople of forms which have a consistant look and also shares SOME similar functionality between the forms.
0
2314
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 example source code can be downloaded here: http://www.blogitek.com/timhaughton/archives/files/User%20Interrogator%20And%20TDD.zip The article text is below. Not sure what it will do to the formatting when
19
4109
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 the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can easily understand a newbie using bound controls or someone with a tight deadline. I guess I need...
12
1974
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
2343
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 through the forms collection, bringing forms to the front with API via hWnd, et.. and so on. The problem is that users are loosing windows behind others and I thought I would put a list together on an existing left handed menu of (i.e.) "My open...
14
3367
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 I'll make the inactive forms invisible but this is creating a memory corruption problem when user close the form2 or form3 and not the formMain. My main form has a Next button which makes the main form invisible and starts a new form which I'll...
19
248271
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 this data is essential to any developer. This article is a basic tutorial on how to user HTML Forms, the most common method of data collection. Assumptions - Basic HTML knowledge. - Basic PHP knowledge. HTML Forms A common and simple way of...
12
11112
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. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
21
3386
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 a zipcode that is unknown this form will open. I don't want users to modify any of this customers data until they close the zipcode form. Normally this can accomplished using a modal form, however this prevents me from opening a new copy of...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.