SlideShare a Scribd company logo
1 of 31
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.
5
Panel Demo
The Panel control is a container for other
controls.
Use it to put a border around a group of
related controls.
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.
Add Default.aspx
9
Panel Demo
 View the Toolbox.
 Expand the Standard section.
 Add a Panel to the <div>.
 Set its properties as shown on the next slide.
10
The Panel
11
Source View
12
Edit Source
position:static means “no special positioning”
Follow the normal rules of HTML
13
Add Text Inside Panel
14
App Running
Try resizing the window.
15
What the Browser Received
16
Effects of Properties
Experiment with property values:
HorizontalAlign
Wrap
Height
Width
Padding
17
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
18
Dynamic Controls
</asp:Panel>
<table>
<tr>
<td>
Number of Labels:
</td>
<td>
<asp:DropDownList ID="ddlLabels" runat="server">
<asp:ListItem Text="0" Value="0" />
<asp:ListItem Text="1" Value="1" />
<asp:ListItem Text="2" Value="2" />
<asp:ListItem Text="3" Value="3" />
<asp:ListItem Text="4" Value="4" />
</asp:DropDownList>
</td>
</tr>
19
Dynamic Controls
<tr>
<td>
Number of TextBoxes:
</td>
<td>
<asp:DropDownList ID="ddlBoxes" runat="server">
<asp:ListItem Text="0" Value="0" />
<asp:ListItem Text="1" Value="1" />
<asp:ListItem Text="2" Value="2" />
<asp:ListItem Text="3" Value="3" />
<asp:ListItem Text="4" Value="4" />
</asp:DropDownList>
</td>
</tr>
20
Dynamic Controls
<tr>
<td colspan=2> &nbsp; </td>
</tr>
<tr>
<td>
<asp:CheckBox id="cbHide" runat="server"
text="Hide Panel" />
</td>
<td>
<asp:Button ID="btnRefreshPanel" runat="server"
text="Refresh Panel" />
</td>
</tr>
</table>
21
Design View
22
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("<br />"));
}
}
Try it!
23
Page in Chrome
24
After Clicking “Refresh Panel”
25
Hiding the Panel
After clicking “Refresh Panel”
26
Refresh Panel Button
We didn’t add an event handler for the
“Refresh Panel” button.
How did it work?
Why was it needed?
27
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("<br />"));
}
28
After Clicking “Refresh Panel”
29
Automatic Scrollbar
Resize window. Look at the effect of making the
window wider and more narrow.
30
Automatic Scrollbar
End of Presentation
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

More Related Content

Similar to SynapseIndia creating asp controls programatically development

Custom Controls in ASP.net
Custom Controls in ASP.netCustom Controls in ASP.net
Custom Controls in ASP.netkunj desai
 
.Net course-in-mumbai-ppt
.Net course-in-mumbai-ppt.Net course-in-mumbai-ppt
.Net course-in-mumbai-pptvibrantuser
 
ASP.NET Session 9
ASP.NET Session 9ASP.NET Session 9
ASP.NET Session 9Sisir Ghosh
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controlsRaed Aldahdooh
 
12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17Vivek chan
 
ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsRandy Connolly
 
Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.netSireesh K
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04Mani Chaubey
 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaJignesh Aakoliya
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletMitchinson
 
Inside WSS sample shots
Inside WSS sample shotsInside WSS sample shots
Inside WSS sample shotsSøren Raarup
 
Creating web api and consuming- part 1
Creating web api and consuming- part 1Creating web api and consuming- part 1
Creating web api and consuming- part 1Dipendra Shekhawat
 
Lab: Developing with the extension library
Lab: Developing with the extension libraryLab: Developing with the extension library
Lab: Developing with the extension libraryWorkFlowStudios
 
Previous weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docxPrevious weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docxkeilenettie
 
Csphtp1 12
Csphtp1 12Csphtp1 12
Csphtp1 12HUST
 

Similar to SynapseIndia creating asp controls programatically development (20)

Visual studio 2008 asp net
Visual studio 2008 asp netVisual studio 2008 asp net
Visual studio 2008 asp net
 
Custom Controls in ASP.net
Custom Controls in ASP.netCustom Controls in ASP.net
Custom Controls in ASP.net
 
.Net course-in-mumbai-ppt
.Net course-in-mumbai-ppt.Net course-in-mumbai-ppt
.Net course-in-mumbai-ppt
 
ASP.NET Session 9
ASP.NET Session 9ASP.NET Session 9
ASP.NET Session 9
 
Asp PPT (.NET )
Asp PPT (.NET )Asp PPT (.NET )
Asp PPT (.NET )
 
Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
ASP.NET - Web Programming
ASP.NET - Web ProgrammingASP.NET - Web Programming
ASP.NET - Web Programming
 
Asp.net server controls
Asp.net server controlsAsp.net server controls
Asp.net server controls
 
12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17
 
ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server Controls
 
Ajax control asp.net
Ajax control asp.netAjax control asp.net
Ajax control asp.net
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04
 
Overview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company indiaOverview of ASP.Net by software outsourcing company india
Overview of ASP.Net by software outsourcing company india
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutlet
 
Inside WSS sample shots
Inside WSS sample shotsInside WSS sample shots
Inside WSS sample shots
 
ASP DOT NET
ASP DOT NETASP DOT NET
ASP DOT NET
 
Creating web api and consuming- part 1
Creating web api and consuming- part 1Creating web api and consuming- part 1
Creating web api and consuming- part 1
 
Lab: Developing with the extension library
Lab: Developing with the extension libraryLab: Developing with the extension library
Lab: Developing with the extension library
 
Previous weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docxPrevious weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docx
 
Csphtp1 12
Csphtp1 12Csphtp1 12
Csphtp1 12
 

More from Synapseindiappsdevelopment

Synapse india elance top in demand in it skills
Synapse india elance top in demand in it skillsSynapse india elance top in demand in it skills
Synapse india elance top in demand in it skillsSynapseindiappsdevelopment
 
SynapseIndia dotnet web development architecture module
SynapseIndia dotnet web development architecture moduleSynapseIndia dotnet web development architecture module
SynapseIndia dotnet web development architecture moduleSynapseindiappsdevelopment
 
SynapseIndia dotnet development platform overview
SynapseIndia  dotnet development platform overviewSynapseIndia  dotnet development platform overview
SynapseIndia dotnet development platform overviewSynapseindiappsdevelopment
 
SynapseIndia dotnet web applications development
SynapseIndia  dotnet web applications developmentSynapseIndia  dotnet web applications development
SynapseIndia dotnet web applications developmentSynapseindiappsdevelopment
 
SynapseIndia dotnet website security development
SynapseIndia  dotnet website security developmentSynapseIndia  dotnet website security development
SynapseIndia dotnet website security developmentSynapseindiappsdevelopment
 
SynapseIndia mobile apps deployment framework internal architecture
SynapseIndia mobile apps deployment framework internal architectureSynapseIndia mobile apps deployment framework internal architecture
SynapseIndia mobile apps deployment framework internal architectureSynapseindiappsdevelopment
 
SynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseindiappsdevelopment
 
SynapseIndia mobile apps deployment framework architecture
SynapseIndia mobile apps deployment framework architectureSynapseIndia mobile apps deployment framework architecture
SynapseIndia mobile apps deployment framework architectureSynapseindiappsdevelopment
 
SynapseIndia dotnet client library Development
SynapseIndia dotnet client library DevelopmentSynapseIndia dotnet client library Development
SynapseIndia dotnet client library DevelopmentSynapseindiappsdevelopment
 

More from Synapseindiappsdevelopment (20)

Synapse india elance top in demand in it skills
Synapse india elance top in demand in it skillsSynapse india elance top in demand in it skills
Synapse india elance top in demand in it skills
 
SynapseIndia dotnet web development architecture module
SynapseIndia dotnet web development architecture moduleSynapseIndia dotnet web development architecture module
SynapseIndia dotnet web development architecture module
 
SynapseIndia dotnet module development part 1
SynapseIndia  dotnet module development part 1SynapseIndia  dotnet module development part 1
SynapseIndia dotnet module development part 1
 
SynapseIndia dotnet framework library
SynapseIndia  dotnet framework librarySynapseIndia  dotnet framework library
SynapseIndia dotnet framework library
 
SynapseIndia dotnet development platform overview
SynapseIndia  dotnet development platform overviewSynapseIndia  dotnet development platform overview
SynapseIndia dotnet development platform overview
 
SynapseIndia dotnet development framework
SynapseIndia  dotnet development frameworkSynapseIndia  dotnet development framework
SynapseIndia dotnet development framework
 
SynapseIndia dotnet web applications development
SynapseIndia  dotnet web applications developmentSynapseIndia  dotnet web applications development
SynapseIndia dotnet web applications development
 
SynapseIndia dotnet website security development
SynapseIndia  dotnet website security developmentSynapseIndia  dotnet website security development
SynapseIndia dotnet website security development
 
SynapseIndia mobile build apps management
SynapseIndia mobile build apps managementSynapseIndia mobile build apps management
SynapseIndia mobile build apps management
 
SynapseIndia mobile apps deployment framework internal architecture
SynapseIndia mobile apps deployment framework internal architectureSynapseIndia mobile apps deployment framework internal architecture
SynapseIndia mobile apps deployment framework internal architecture
 
SynapseIndia java and .net development
SynapseIndia java and .net developmentSynapseIndia java and .net development
SynapseIndia java and .net development
 
SynapseIndia dotnet development panel control
SynapseIndia dotnet development panel controlSynapseIndia dotnet development panel control
SynapseIndia dotnet development panel control
 
SynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client library
 
SynapseIndia php web development
SynapseIndia php web developmentSynapseIndia php web development
SynapseIndia php web development
 
SynapseIndia mobile apps architecture
SynapseIndia mobile apps architectureSynapseIndia mobile apps architecture
SynapseIndia mobile apps architecture
 
SynapseIndia mobile apps deployment framework architecture
SynapseIndia mobile apps deployment framework architectureSynapseIndia mobile apps deployment framework architecture
SynapseIndia mobile apps deployment framework architecture
 
SynapseIndia mobile apps
SynapseIndia mobile appsSynapseIndia mobile apps
SynapseIndia mobile apps
 
SynapseIndia dotnet development
SynapseIndia dotnet developmentSynapseIndia dotnet development
SynapseIndia dotnet development
 
SynapseIndia dotnet client library Development
SynapseIndia dotnet client library DevelopmentSynapseIndia dotnet client library Development
SynapseIndia dotnet client library Development
 
SynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax DevelopmentSynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax Development
 

Recently uploaded

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 

Recently uploaded (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 

SynapseIndia creating asp controls programatically development

  • 1. 1111 Creating ASPX Controls Programatically
  • 2. 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. 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.
  • 4. 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.
  • 5. 5 Panel Demo The Panel control is a container for other controls. Use it to put a border around a group of related controls. 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. 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. 7 Panel Demo  Create a new C# ASP.NET empty web site with the name Panel_Demo.
  • 9. 9 Panel Demo  View the Toolbox.  Expand the Standard section.  Add a Panel to the <div>.  Set its properties as shown on the next slide.
  • 12. 12 Edit Source position:static means “no special positioning” Follow the normal rules of HTML
  • 16. 16 Effects of Properties Experiment with property values: HorizontalAlign Wrap Height Width Padding
  • 17. 17 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
  • 18. 18 Dynamic Controls </asp:Panel> <table> <tr> <td> Number of Labels: </td> <td> <asp:DropDownList ID="ddlLabels" runat="server"> <asp:ListItem Text="0" Value="0" /> <asp:ListItem Text="1" Value="1" /> <asp:ListItem Text="2" Value="2" /> <asp:ListItem Text="3" Value="3" /> <asp:ListItem Text="4" Value="4" /> </asp:DropDownList> </td> </tr>
  • 19. 19 Dynamic Controls <tr> <td> Number of TextBoxes: </td> <td> <asp:DropDownList ID="ddlBoxes" runat="server"> <asp:ListItem Text="0" Value="0" /> <asp:ListItem Text="1" Value="1" /> <asp:ListItem Text="2" Value="2" /> <asp:ListItem Text="3" Value="3" /> <asp:ListItem Text="4" Value="4" /> </asp:DropDownList> </td> </tr>
  • 20. 20 Dynamic Controls <tr> <td colspan=2> &nbsp; </td> </tr> <tr> <td> <asp:CheckBox id="cbHide" runat="server" text="Hide Panel" /> </td> <td> <asp:Button ID="btnRefreshPanel" runat="server" text="Refresh Panel" /> </td> </tr> </table>
  • 22. 22 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("<br />")); } } Try it!
  • 25. 25 Hiding the Panel After clicking “Refresh Panel”
  • 26. 26 Refresh Panel Button We didn’t add an event handler for the “Refresh Panel” button. How did it work? Why was it needed?
  • 27. 27 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("<br />")); }
  • 29. 29 Automatic Scrollbar Resize window. Look at the effect of making the window wider and more narrow.
  • 31. 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