1111 Creating ASPX Controls Programatically. 2222 Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.

Slides:



Advertisements
Similar presentations
Unit 02. ASP.NET Introduction HTML & Server controls Postbacks Page Lifecycle.
Advertisements

1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
11 User Controls II Chapter Objectives You will be able to Create a realistic reusable user control. Use data binding in a user control. Change.
11 ASP.NET Controls II Beginning ASP.NET 4.0 in C# 2010 Chapter 6.
Web Development in Microsoft Visual Studio Slide 2 Lecture Overview Introduce Visual Studio 2013 Create a first ASP.NET application.
Web-Based Applications
Introduction to ASP.Net ISYS 350. ASP.NET ASP.NET is a server-side technology for creating dynamic web pages. ASP.NET allows you to use a selection of.
Copyright © 2004 ProsoftTraining, All Rights Reserved. Lesson 9: Frames © 2007 Prosoft Learning Corporation All rights reserved ITD 110 Web Page Design.
Copyright © 2004 ProsoftTraining, All Rights Reserved. Lesson 9: HTML Frames.
Chapter 19 – Macromedia Dreamweaver MX 2004
11 ASP.NET Controls Beginning ASP.NET 4.0 in C# 2010 Chapter 6.
ASP.Net, Web Forms and Web Controls 1 Outline Introduction Simple HTTP Transaction System Architecture Creating and Running a Simple Web Form Example Web.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Advanced CSS - Page Layout. Advanced CSS  Compound Selectors:  Is a Dreamweaver term, not a CSS term.  Describes more advanced types of selectors such.
JavaScript & jQuery the missing manual Chapter 11
Chapter 3 Dreamweaver: Part I The Web Warrior Guide to Web Design Technologies.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
HTML, GUI, ASP.NET Rina Zviel-Girshin Lecture 2
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
© Ms. Masihi.  The Dreamweaver Welcome Screen first opens when you start Dreamweaver.  This screen gives you quick access to previously opened files,
Beginning Web Site Development Module 1 – Dynamic Web Site Development Fundamentals of building dynamic Web sites with ASP.NET 2.0 and C# Version.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 4-1 of…
ASP Hello, world. ServerClient Response Request A form.
INSPIRING CREATIVE AND INNOVATIVE MINDS Module 4: Adding Code to a Microsoft ASP.NET Web Form Implementing Code-Behind Pages Adding Event Procedures to.
1 Macromedia Dreamweaver Outline Introduction Macromedia Dreamweaver Text Styles Images and Links Symbols and Lines Tables Forms Scripting in Dreamweaver.
ASP.NET Web Server Controls Basic Web Server Controls.
Web Controls Chapter-7. Page  2 Synopsis  Stepping Up to Web controls  Basic Web control classes  Web control classes  Web control Base class  Units,
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
® IBM Software Group © 2006 IBM Corporation Programmatically Rendering and Hiding JSF Controls This section describes how to hide and show JSF controls.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
CSCI 6962: Server-side Design and Programming Introduction to Active Server Pages.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Domain 3 Understanding the Adobe Dreamweaver CS5 Interface.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
1 CS 3870/CS 5870 Note04 Session Variables and Post Back.
Dynamic Dropdown Lists 1. Objectives You will be able to Use Dropdown Lists to solicit multiple choice user input in an ASPX web page. Populate a Dropdown.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
1 JavaScript Functions and Objects. 2 Objectives You will be able to Use JavaScript functions in JavaScript scripts. Get JavaScript functions executed.
Creating Applets. What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An applet.
ASP.NET 4 Unleashed Chapter 1. .aspx page: contains C# script and HTML code including tags. Listing 1.1 FirstPage.aspx.
Christopher M. Pascucci.NET Programming: WebForm Events.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Asp.NET Core Server Controls. Slide 2 Lecture Overview Understanding the types of ASP.NET controls HTML controls ASP.NET (Web) controls.
Introducing Dreamweaver. Dreamweaver The web development application used to create web pages Part of the Adobe creative suite.
11 ASP.NET Server Controls Beginning ASP.NET in C# and VB Chapter 4.
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
11 Getting Started with ASP.NET Beginning ASP.NET in C# and VB Chapters 1 and 2.
1111 Creating HTML Programatically Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML.
Lecture Set 7 Procedures and Event Handlers Part B - The Structure of an Application Event Handlers.
1 Project 4 Address Lookup. Project 4 Write an ASP.NET app that permits users to retrieve addresses from a potentially large list of addresses. There.
1111 Master Pages Beginning ASP.NET in C# and VB Chapter 6.
Event Handling & Viewstate CS 351 Ed Gellenbeck. Today Review of Web Forms ASP.NET Object Hierarchy Events State Management Page State Session State Application.
11 User Controls Beginning ASP.NET in C# and VB Chapter 8.
Creating a Web Site Creating a new Web site Defining and using folders Creating and editing Web pages Viewing pages in a Web browser.
Beginning ASP.NET in C# and VB Chapter 9
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
ASP.NET Part 2 Instructor: Charles Moen CSCI/CINF 4230.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Creating Consistent Looking Websites
ASP.NET Forms.
Chapter 9 Programming Based on Events
ASP.Net Demo ISYS 350.
Static and Dynamic Web Pages
ASP.NET.
Web Development Using ASP .NET
Presentation transcript:

1111 Creating ASPX Controls Programatically

2222 Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls. Use the Panel control as a container for other controls.

3 Panel Demo Example of dynamically creating controls and adding them to a page. Also using a Panel control as a container for other controls. An alternative way to put new HTML onto a page at run time. Rather than outputting HTML directly, we add control objects to the internal representation of the page in server memory. They output HTML during the “render” phase of the page life cycle on the server.

Adding ASPX Controls Dynamically Think about what would happen if we used Response.Write( ) to add an ASPX control to the page. To add a dynamically created ASPX control to the page we have to add it to the data structure in server memory that is the internal representation of the page. 4

5 Panel Demo The Panel control is a container for other controls. Use it to put a border around a group of related controls. We can set styling, position, and visibility for the entire group by setting properties of the panel. Provides a convenient way to add controls to the page dynamically.

6 Panel Demo We will create a page with a panel control containing some static text. Dropdown lists permit the user to Add 1 – 4 labels to the panel. Add 1 – 4 textboxes to the panel. CheckBox permits user to hide the panel.

7 Panel Demo Create a new C# ASP.NET empty web site with the name Panel_Demo.

8 Panel Demo

Add New Item 9

Add Web Form Default.aspx 10

11 Add a Panel View the Toolbox. Expand the Standard section. Add a Panel to the. Use handles on the panel in design view to resize it. Set its properties in the Properties window on the right side of the design surface. As shown in a later slide

Adding a Panel 12 Double click on"Panel" in the Toolbox to add a panel at the cursor position.

New Panel in Source View 13

14 New Panel in Design View Use handles on the panel to resize it.

15 Source View

16 Edit Source position:static means “no special positioning” Follow the normal rules of HTML

Add Text Inside Panel <asp:Panel ID="pnlDynamic" runat="server" BackColor="Beige" BorderStyle="Solid" Font-Names="Courier New" Height="287px" Width="80%" ScrollBars="Auto" Style="position:static; padding: 20px"> This is static content in the panel. This text is here to show the effect of changing the padding values. Padding value can be specified in terms of pixels (px), centimeters (cm), or percentage of the panel's width (%). 17

18 Text Inside Panel

19 App Running Try resizing the window.

20 What the Browser Received... became...

21 Effects of Properties Experiment with property values: HorizontalAlign Wrap Height Width Padding

22 Dynamic Controls Let’s add some controls that will have the effect of adding other controls to the panel dynamically. A new DropDown List will add a specified number of labels to the panel. Options for 0 – 4 labels A second new DropDownList will add a specified number of CheckBoxes. Options for 0 – 4 CheckBoxes Also a CheckBox that will hide the panel And a Button to refresh the panel

23 Dynamic Controls Number of Labels:

24 Dynamic Controls Number of TextBoxes:

25 Dynamic Controls <asp:CheckBox id="cbHide" runat="server" text="Hide Panel" /> <asp:Button ID="btnRefreshPanel" runat="server" text="Refresh Panel" />

26 Design View

27 Code for Dynamic Update using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { pnlDynamic.Visible = !cbHide.Checked; int numLabels = int.Parse(ddlLabels.SelectedItem.Value); for (int i = 1; i <= numLabels; i++) { Label lbl = new Label(); lbl.Text = "Label" + i.ToString(); lbl.ID = "Label" + i.ToString(); pnlDynamic.Controls.Add(lbl); pnlDynamic.Controls.Add(new LiteralControl(" ")); } Try it!

28 Page in Chrome Select Number of Labels and then click "Refresh Panel".

29 After Clicking “Refresh Panel” Dynamically added labels. Click Hide Panel checkbox and then "Refresh Panel".

30 Hiding the Panel After clicking “Refresh Panel” Click Hide Panel checkbox again and then "Refresh Panel" to bring the panel back.

31 Refresh Panel Button We didn’t add an event handler for the “Refresh Panel” button. How did it work? Why was an event handler not needed?

32 Code to Add TextBoxes Add to Page_Load: // Generate TextBox controls int numBoxes = int.Parse(ddlBoxes.SelectedItem.Value); for (int i = 1; i <= numBoxes; i++) { TextBox tb = new TextBox(); tb.Text = "TextBox" + i.ToString(); tb.ID = "TextBox" + i.ToString(); pnlDynamic.Controls.Add(tb); pnlDynamic.Controls.Add(new LiteralControl(" ")); }

33 After Clicking “Refresh Panel”

34 Automatic Scrollbar Resize window. Look at the effect of making the window wider and more narrow.

Summary We can create ASPX controls dynamically using C# code and add them to the page before the page is translated into HTML. We can dynamically modify controls defined in the.aspx file in the Page_Load event handler. End of Presentation 35