What about invisible-stealth forms in ASP.Net....?

Discussion in 'C#' started by JEP_Dude, Feb 25, 2009.

  1. #1
    Hey there....!

    I'm new to ASP.Net. I'm getting use to only using one form, but I don't like it.

    I was wondering if anyone has tried to use a type of hidden form? We could call it some kind of stealth form because it wouldn't be created or defined like a standard Web Form. This one could be defined and created as a collection of form controls that, when visible, collectively operate like a form connected together by possibly a table grid with all the rectangles filled in. Some could be filled in with labels, some with buttons, and some others with textboxs, and so on.

    This collection could be invisible while directly over various other controls of a standard web form. Yet, when the time comes and this stealth form is needed, the controls below could be made invisible and this second form would be made visible with its controls.

    So it would appear and function like a regular or smaller sized web form, but it would be hidden until necessary.

    The question is ... has any one tried this technique before? ... and how well does it work?

    Thanks is advance.

    May you have a blessed day.
     
    JEP_Dude, Feb 25, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    I'm not exactly sure what you mean, but you can only have one form within an asp.net application. But you can seperate parts of the form using <asp:panel>. This makes it so when the user presses enter rather than click 'Submit' it will still trigger the correct event, and you can also hide Panels.

    Here is the front-end of an example:
    
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:Panel id="panel1" runat="server" Visible="true" DefaultButton="submit_form1">
            <asp:TextBox ID="TextBox1" runat="server">form1 textbox</asp:TextBox>
            <asp:Button ID="submit_form1" runat="server" Text="Submit" />
        
        </asp:Panel>
        <asp:Panel id="panel2" runat="server" Visible="false" DefaultButton="submit_form2">
            <asp:TextBox ID="TextBox2" runat="server">form2 textbox</asp:TextBox>
            <asp:Button ID="submit_form2" runat="server" Text="Submit" />
        </asp:Panel>
        </div>
        <asp:Label ID="Label1" runat="server" Text="Form Submission Complete" 
            Visible="False"></asp:Label>
        </form>
    </body>
    </html>
    
    Code (markup):
    And this is the code-behind.
    
    
    Partial Class _Default
        Inherits System.Web.UI.Page
    
        Protected Sub submit_form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit_form1.Click
            panel1.Visible = False
            panel2.Visible = True
        End Sub
    
        Protected Sub submit_form2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit_form2.Click
            panel1.Visible = False
            panel2.Visible = False
            MsgBox(TextBox1.Text)
            MsgBox(TextBox2.Text)
            Label1.Visible = True
        End Sub
    End Class
    
    Code (markup):
    Is this what you are meaning to do?
     
    camjohnson95, Feb 25, 2009 IP
  3. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Note: the DefaultButton property of the <asp:panel control. This determines what event will be triggered when the enter key is pressed by the user to submit the form.
     
    camjohnson95, Feb 25, 2009 IP
  4. JEP_Dude

    JEP_Dude Peon

    Messages:
    121
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    camjohnson95,

    Thanks for the code! I'm so new with ASP.Net that I really can't guess what your talking about. I need to see for myself.

    I think you got the big picture of what I was talking about. But let me take it a bit further.

    Has anyone designed a routine(s) that would automatically calculate the specific details needed for the panel's placement and each individual control so the design and operation on the whole page would be simplified?

    With that, why would I care for a second page?

    Thanks in advance.

    May you have a blessed day.
     
    JEP_Dude, Feb 26, 2009 IP
  5. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #5
    If a panel is not visible it will not take up an space. So if you have two panels, and only one is visible, yes you could have one page rather then two.
    Panels can also be moved anywhere on the page by using the CSS. e.g:
    <asp:panel id="panel1" runat="server" Visible="true" DefaultButton="submit_form1" style="position:absolute; top: 200px; left: 200px;">

    This would move the panel 200pixels from the top and 200pixels from the left.
     
    camjohnson95, Feb 26, 2009 IP