Need good design for a multi-part form in .NET -
I have a set of screens in C # / ASP where the user enters information to make it more user-friendly For it it has been divided into several parts. It used to be in different pages, but managing it was very difficult, because all the information is very related. So it was turned into a panel in a panel that we show and hide based on the user's progress.
We want to be able to move things very smoothly. At present we need to copy-paste that is not particularly fast, but this error is prone to error. Is there a better way to handle multi-part forms which makes them more modular?
(As a backdrop, I'm mostly Java developer, which is working with .NET recently)
A .ascx
file, also known as UserControl
is a good way to normalize during a project HTML / code is reused, they are essentially just one container for other .NET controls.
So we excuse you that you have a very simple form, where you are asking for only one person's name and age, and for some reason you want to use it in the page or many Many times on pages ...
UserControl1.ascx
Markup:
& asp: label runat = "server" id = "lbl name "Lesson =" What is the person's name? "AssociatedControlID =" txtName "& gt; & Lt; / ASP: Labels & gt; & Lt; ASP: Text Box Runat = "Server" id = "txtName" & gt; & Lt; / Asp: text box & gt; & Lt; Asp: label runat = "server" id = "lblAge" text = "What is the person's age?" AssociatedControlID = "txtAge" & gt; & Lt; / ASP: Labels & gt; & Lt; ASP: text box runat = "server" id = "txtAge" & gt; & Lt; / Asp: text box & gt; & Lt; ASP: Button Runat = "Server" id = "Submit BTN" text = "Submit" onclick = "BTNSBTCCClick"> & Lt; / Asp: button & gt;
Back code:
Private person _Person; Protected void btnSubmit_Clicked (object sender, EventArgs args) {_Person = new person () {name = txtName.Text, age = txtAge.Text}; } Public Person GetPerson () {Return _Person; }
Then on any other page you leave this user under control, and you can reference it like this:
Default.aspx
Markup:
& lt;% @ Register src = "UserControl1.ascx" tag name = "UserControl1" tagprofix = "uc1"%> & Lt; Html & gt; ... blah blah ... & lt; P & gt; Tell us about you & lt; / P & gt; & Lt; Uc1: UserControl1 id = "ucYou" runat = "server" /> & Lt; P & gt; Tell us about your friend & lt; / P & gt; & Lt; Uc1: UserControl1 ID = "ucYourFriend" runat = "server" /> .. blah blah & lt; / Html & gt;
Behind the code:
protected void SomeMethodThatSavesPage () {// Other stuff you person = ucYou.GetPerson (); Person your visit = ucYourFriend.GetPerson (); }
Page Directive
As Robert reminds me in comments, you need to make sure that the page that uses UserControl is correct on the top The page has directions. If you are in Design view and drag UserControl on the page, Visual Studio will handle it for you. Otherwise, you have to include it manually.
Comments
Post a Comment