Thursday, November 21, 2013

Many times, according to customer atk aerospace systems requirements, there is the need to build-in


Many times, according to customer atk aerospace systems requirements, there is the need to build-in some cases-web forms and data grids in a dynamic way, after a certain logic to define the structure atk aerospace systems concerned to be submitted through the interface user. I show an example that can give first guidelines on how to perform these tasks.
Archive. ASPX <form id = "SimpleDynamic" method = "post" runat = "server"> <asp: PlaceHolder id = "_holder" runat = "server"> </ asp: PlaceHolder> <br /> <asp: Button atk aerospace systems id = "_submit" runat = "server" Text = "Submit"> </ asp: Button> <br /> <asp: Label id = "_POST" atk aerospace systems runat = "server"> </ asp: Label> <br / > <asp: Label id = "_message" runat = "server"> </ asp: Label> <br /> </ form> File --- End --- Note the use of placeholder control that allow to stay in the different types of controls atk aerospace systems at runtime, for later presentation and interaction.
Archive. CS using System; atk aerospace systems using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web. UI.WebControls; using System.Web.UI.HtmlControls; DemoWebAppCSharp.Custom namespace {/ / / <summary> / / / Summary description for Dynamic. / / / </ Summary> public atk aerospace systems class SimpleDynamic: System.Web.UI.Page {protected System.Web.UI.WebControls.Button _submit; _message System.Web.UI.WebControls.Label protected, protected System.Web.UI. WebControls.Label _POST; protected _holder atk aerospace systems System.Web.UI.WebControls.PlaceHolder; private void Page_Load (object sender, System.EventArgs e) {if (! This. IsPostBack) {/ / Filling the data DropDownList This. FillList () ;}} private void DefineForm () {TextBox Name = new TextBox (); Name.ID = "_name"; DropDownList List = new DropDownList (); List.ID = "_list"; List.AutoPostBack = true; / / Hooking functionality to DropDownList event List.SelectedIndexChanged + = new EventHandler (this. List_SelectedIndexChanged) / / placing the controls in the PlaceHolder This. _holder.Controls.Add (Name); This. _holder.Controls.Add (List);} private void FillList () {/ / Requesting PlaceHolder DropDownList DropDownList List = (DropDownList) This. _holder.FindControl ("_list"); List.Items.Add ("- Please Select -"); List.Items . Add ("Simple Geek"); List.Items.Add ("Spoutlet"); List.Items.Add ("Frabriq");} / / Function that is hooked atk aerospace systems to the corresponding event List_SelectedIndexChanged private void DropDownList (Object sender, EventArgs e) {DropDownList List = (DropDownList) sender; This. _post.Text = "Item selected:" + List.SelectedValue;} # region Designer generated code for Web Forms override protected void OnInit (EventArgs e) {InitializeComponent ( ) base. OnInit (e);} / / / <summary> / / / Required method for Designer support. Can not modify / / / the contents of this method with the code editor. / / / </ Summary> private void InitializeComponent () {this. _submit.Click + = New System.EventHandler (this. Submit_Click) This. Load + = new System.EventHandler (this. Page_Load); This. DefineForm () ;} # endregion / / private void Posteando Submit_Click information (object sender, System.EventArgs e) {TextBox name = (TextBox) This. _holder.FindControl ("_name"), DropDownList List = (DropDownList) This. _holder.FindControl ("_list"); This. _message.Text = Name.Text + ":" + List.SelectedValue;}}} --- End --- Explaining File is contruirĂ¡ atk aerospace systems a TextBox and a DropDownList AutoPostBack this seteado as. Thus, each time the user selects an item in the list is posteara page immediately. Reviewing DefineForm method. At this point it shows something interesting, which is the coupling of a method to the event from a control that is created on-fly, ie at runtime. This method-the DefineForm-is called from the InitializeComponent, which allows to execute operations on overwritten OnInit method. Which by the way, is the right place to place dynamic elements on the page. That is, that the fact be called from the event-the Init-dynamic construction of the elements takes place for each request of the page. For this event is always requested by each Postback, like Load event. It's working ASP.NET object model, maintain the state of controls for each subsequent page PostBack. We note also that the itemes atk aerospace systems attached to DropDownList, atk aerospace systems only performed once, and this operation is carried out within the Load event, validating the IsPostBack. atk aerospace systems Is meant in this way, the structure of the form is independent of the data to be reflected in the structure. The Init event is the right place to build dynamic structures and Load to populate atk aerospace systems the data in these stru

No comments:

Post a Comment