-----------------------------------------------------------

New Message on MumbaiUserGroup

-----------------------------------------------------------
From: Edwag_Teejihba
Message 4 in Discussion

This is an Extract from the Book:          Programming Microsoft ASP.NET          by 
Dino Esposito             ISBN : 0735619034         Microsoft Press   Hope so this 
will help you.    Multiple Forms 
As mentioned, the SFI model is the default in ASP.NET and plays a key role in the 
automatic state management mechanism we described in Chapter 2. Some pages, though, 
would have a more consistent and natural design if they could define multiple logical 
forms. In this context, a logical form is a logically related group of input controls. 
For example, think of a login page for restricted areas of a Web site. Registered 
users just type in their user name and password and connect. Unregistered users need 
to fill out a form before they're given the parameters to connect. How do you code 
this? Let's review a few options. 
In ASP, you can use two forms, each posting to a different page. The schema is 
outlined in Figure 4-1.  
Figure 4-1: Each form posts to a different page.  
This solution is impracticable in ASP.NET unless you resort to a kind of pseudo-trick 
that basically consists of not using ASP.NET server controls. (More on this in a 
moment.) More apt to the ASP.NET programming style is the solution depicted in Figure 
4-2.  
Figure 4-2: One physical <form> tag contains multiple logical forms. All logical forms 
post to the same page and hide any unneeded user interface element.  
A unique page is involved and contains a single <form> tag. Within the opening and 
closing tags of the form, two or more groups of logically related controls find their 
place. Each group can post back using either a classic submit button or a hyperlink 
bound to some script code�the entity that ASP.NET renders as a link button. Although 
the various groups are not forms in the technical sense of the word, they do behave 
like forms. All groups post to the same page, but the ASP.NET infrastructure 
guarantees both state maintenance and the execution of a piece of code specific to the 
group that caused the post. Each link button is associated with a server-side method 
that runs when the page posts back as the result of a click. Functionally speaking, 
the mechanism is in no way different than the ASP implementation. Furthermore, the 
programming model enjoys a higher abstraction layer and handy features such as view 
state and server-side control programming.  Toggling the Control's Visibility 
How can you update the user interface of the HTML being generated? You should know the 
answer immediately if you're somewhat familiar with Dynamic HTML (DHTML) and 
client-side programming. Otherwise, just read on. 
ASP.NET server controls can programmatically be hidden from and restored to view. 
Controls with the Visible property set to false are ignored by the ASP.NET parser, and 
no HTML code will ever be generated for them. It turns out that this feature is key to 
dynamically creating the user interface of a page, piece by piece. So with reference 
to Figure 4-2, you design your login page to contain three blocks of HTML code: the 
login form, registration form, and restricted area. The first time you show the 
page�that is, when IsPostBack is set to false�the former two blocks are displayed 
while the restricted area remains invisible. Next, the user clicks to either log in or 
register. The page posts back to execute ad hoc code. Once you have registered the new 
user or checked the credentials of a known user, you simply toggle off the visibility 
of the forms and toggle on that of the restricted area. Et voil�!     Note   
Playing with the visibility of controls is a key technique in Dynamic HTML and is the 
underpinning to many animation effects you see on Web sites when you navigate with 
Internet Explorer. Typically, cascading menus and collapsible views are obtained by 
putting a hidden <div> tag below the clickable text. When you click on the text, some 
script code simply toggles the display attribute of the <div> tag and the browser does 
the rest, refreshing the page.   Multiple <form> Tags on a Page 
For completeness, let's see how to create an ASP.NET page that really contains 
multiple <form> tags. Of course, only one of these tags can have the runat attribute 
set to server, and only for the controls contained therein can ASP.NET provide view 
state management and postback events. Let's consider the following ASP.NET page: 
<html> <body>     <form runat="server">         <asp:textbox runat="server" 
id="theTextBox" />         <asp:button runat="server" text="Post back" />     </form>  
       <form method="post" action="another.aspx">         <input type="text" 
name="SecondField " />         <input type="submit" id="submit1" value="another.aspx" 
/>     </form>         <form method="post" action="multiforms.aspx">         <input 
type="text" name="ThirdField" />         <input type="submit" id="submit2" value="This 
page" />     </form> </body> </html> 
As you can see, the second and third <form> tags are not marked runat, meaning that 
ASP.NET will treat them as plain text to output verbatim. When you click on the 
submit1 button, the browser navigates to another.aspx�a different ASP.NET page that 
knows nothing about the main page's controls. You can still retrieve values from the 
referrer page by using the old ASP programming style.<% @Page Language="C#" %> <script 
runat="server"> void Page_Load(object sender, EventArgs e) {     
Response.Write(Request.Form["SecondField"]); } </script> 
Note also that when you use the ASP.NET form to post back, the content of the other 
text boxes is cleared. The same thing happens when you submit form data using the 
third button�the submit button of an HTML form that posts to the same page. Why 
doesn't ASP.NET work as usual? It's simple: there's no view-state information for the 
controls in the third form. That's the importance of working the ASP.NET way.      
Important   
You can have multiple server-side forms in your ASP.NET page as long as only one at a 
time is visible. For example, a page with, say, three <form> tags marked to run at the 
server is allowed, but only one of them can be actually rendered. Given the dynamics 
of page rendering, an exception is thrown if more than one HtmlForm control attempts 
to render. By playing with the Visible property of the form controls, you can change 
the active server form during the page lifetime. This approach mimics that of ASP.NET 
mobile controls. (See Chapter 11.) This trick doesn't really solve the problem of 
having multiple active forms, but it can be helpful sometimes.

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/mumbaiusergroup/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to