SlideShare une entreprise Scribd logo
1  sur  6
ASP.NET Web Forms

All server controls must appear within a <form> tag, and the <form> tag must contain
the runat=quot;serverquot; attribute.



ASP.NET Web Forms

All server controls must appear within a <form> tag, and the <form> tag must contain the
runat=quot;serverquot; attribute. The runat=quot;serverquot; attribute indicates that the form should be processed
on the server. It also indicates that the enclosed controls can be accessed by server scripts:

<form runat=quot;serverquot;>
...HTML + server controls
</form>

Note: The form is always submitted to the page itself. If you specify an action attribute, it is
ignored. If you omit the method attribute, it will be set to method=quot;postquot; by default. Also, if you do
not specify the name and id attributes, they are automatically assigned by ASP.NET.

Note: An .aspx page can only contain ONE <form runat=quot;serverquot;> control!

If you select view source in an .aspx page containing a form with no name, method, action, or id
attribute specified, you will see that ASP.NET has added these attributes to the form. It looks
something like this:

<form name=quot;_ctl0quot; method=quot;postquot; action=quot;page.aspxquot; id=quot;_ctl0quot;>
...some code
</form>


Submitting a Form

A form is most often submitted by clicking on a button. The Button server control in ASP.NET has
the following format:

<asp:Button id=quot;idquot; text=quot;labelquot; OnClick=quot;subquot; runat=quot;serverquot; />

The id attribute defines a unique name for the button and the text attribute assigns a label to the
button. The onClick event handler specifies a named subroutine to execute.

In the following example we declare a Button control in an .aspx file. A button click runs a
subroutine which changes the text on the button:




ASP .NET Maintaining the ViewState
You may save a lot of coding by maintaining the ViewState of the objects in your Web
Form.



Maintaining the ViewState

When a form is submitted in classic ASP, all form values are cleared. Suppose you have submitted a
form with a lot of information and the server comes back with an error. You will have to go back to
the form and correct the information. You click the back button, and what happens.......ALL form
values are CLEARED, and you will have to start all over again! The site did not maintain your
ViewState.

When a form is submitted in ASP .NET, the form reappears in the browser window together with all
form values. How come? This is because ASP .NET maintains your ViewState. The ViewState
indicates the status of the page when submitted to the server. The status is defined through a
hidden field placed on each page with a <form runat=quot;serverquot;> control. The source could look
something like this:

<form name=quot;_ctl0quot; method=quot;postquot; action=quot;page.aspxquot; id=quot;_ctl0quot;>
<input type=quot;hiddenquot; name=quot;__VIEWSTATEquot;
value=quot;dDwtNTI0ODU5MDE1Ozs+ZBCF2ryjMpeVgUrY2eTj79HNl4Q=quot; />
.....some code
</form>

Maintaining the ViewState is the default setting for ASP.NET Web Forms. If you want to NOT
maintain the ViewState, include the directive <%@ Page EnableViewState=quot;falsequot; %> at the top of
an .aspx page or add the attribute EnableViewState=quot;falsequot; to any control.

Look at the following .aspx file. It demonstrates the quot;oldquot; way to do it. When you click on the
submit button, the form value will disappear:

<html>
<body>
<form action=quot;demo_classicasp.aspxquot; method=quot;postquot;>
Your name: <input type=quot;textquot; name=quot;fnamequot; size=quot;20quot;>
<input type=quot;submitquot; value=quot;Submitquot;>
</form>
<%
dim fname
fname=Request.Form(quot;fnamequot;)
If fname<>quot;quot; Then
Response.Write(quot;Hello quot; & fname & quot;!quot;)
End If
%>
</body>
</html>

Example

Here is the new ASP .NET way. When you click on the submit button, the form value will NOT
disappear:

<script runat=quot;serverquot;>
Sub submit(sender As Object, e As EventArgs)
lbl1.Text=quot;Hello quot; & txt1.Text & quot;!quot;
End Sub
</script>
<html>
<body>
<form runat=quot;serverquot;>
Your name: <asp:TextBox id=quot;txt1quot; runat=quot;serverquot; />
<asp:Button OnClick=quot;submitquot; Text=quot;Submitquot; runat=quot;serverquot; />
<p><asp:Label id=quot;lbl1quot; runat=quot;serverquot; /></p>
</form>
</body>
</html>




ASP .NET - The TextBox Control

The TextBox control is used to create a text box where the user can input text.



The TextBox Control

The TextBox control is used to create a text box where the user can input text.

The TextBox control's attributes and properties are listed in our web controls reference page.

The example below demonstrates some of the attributes you may use with the TextBox control:

Example

<html>
<body>

<form runat=quot;serverquot;>

A basic TextBox:
<asp:TextBox id=quot;tb1quot; runat=quot;serverquot; />
<br /><br />

A password TextBox:
<asp:TextBox id=quot;tb2quot; TextMode=quot;passwordquot; runat=quot;serverquot; />
<br /><br />

A TextBox with text:
<asp:TextBox id=quot;tb4quot; Text=quot;Hello World!quot; runat=quot;serverquot; />
<br /><br />

A multiline TextBox:
<asp:TextBox id=quot;tb3quot; TextMode=quot;multilinequot; runat=quot;serverquot; />
<br /><br />

A TextBox with height:
<asp:TextBox id=quot;tb6quot; rows=quot;5quot; TextMode=quot;multilinequot;
runat=quot;serverquot; />
<br /><br />

A TextBox with width:
<asp:TextBox id=quot;tb5quot; columns=quot;30quot; runat=quot;serverquot; />
</form>

</body>
</html>


Add a Script

The contents and settings of a TextBox control may be changed by server scripts when a form is
submitted. A form can be submitted by clicking on a button or when a user changes the value in the
TextBox control.

In the following example we declare one TextBox control, one Button control, and one Label control
in an .aspx file. When the submit button is triggered, the submit subroutine is executed. The submit
subroutine writes a text to the Label control:

<script runat=quot;serverquot;>
Sub submit(sender As Object, e As EventArgs)
lbl1.Text=quot;Your name is quot; & txt1.Text
End Sub
</script>
<html>
<body>
<form runat=quot;serverquot;>
Enter your name:
<asp:TextBox id=quot;txt1quot; runat=quot;serverquot; />
<asp:Button OnClick=quot;submitquot; Text=quot;Submitquot; runat=quot;serverquot; />
<p><asp:Label id=quot;lbl1quot; runat=quot;serverquot; /></p>
</form>
</body>
</html>

Example

In the following example we declare one TextBox control and one Label control in an .aspx file.
When you change the value in the TextBox and either click outside the TextBox or press the Tab
key, the change subroutine is executed. The submit subroutine writes a text to the Label control:

<script runat=quot;serverquot;>
Sub change(sender As Object, e As EventArgs)
lbl1.Text=quot;You changed text to quot; & txt1.Text
End Sub
</script>
<html>
<body>
<form runat=quot;serverquot;>
Enter your name:
<asp:TextBox id=quot;txt1quot; runat=quot;serverquot;
text=quot;Hello World!quot;
ontextchanged=quot;changequot; autopostback=quot;truequot;/>
<p><asp:Label id=quot;lbl1quot; runat=quot;serverquot; /></p>
</form>
</body>
</html>
ASP.NET - The Button Control


The Button control is used to display a push button.



The Button Control

The Button control is used to display a push button. The push button may be a submit button or a
command button. By default, this control is a submit button.

A submit button does not have a command name and it posts the page back to the server when it is
clicked. It is possible to write an event handler to control the actions performed when the submit
button is clicked.

A command button has a command name and allows you to create multiple Button controls on a
page. It is possible to write an event handler to control the actions performed when the command
button is clicked.

The Button control's attributes and properties are listed in our web controls reference page.

The example below demonstrates a simple Button control:

<html>
<body>

<form runat=quot;serverquot;>
<asp:Button id=quot;b1quot; Text=quot;Submitquot; runat=quot;serverquot; />
</form>
</body>
</html>


Add a Script

A form is most often submitted by clicking on a button.

In the following example we declare one TextBox control, one Button control, and one Label control
in an .aspx file. When the submit button is triggered, the submit subroutine is executed. The submit
subroutine writes a text to the Label control:

<script runat=quot;serverquot;>
Sub submit(sender As Object, e As EventArgs)
lbl1.Text=quot;Your name is quot; & txt1.Text
End Sub
</script>
<html>
<body>
<form runat=quot;serverquot;>
Enter your name:
<asp:TextBox id=quot;txt1quot; runat=quot;serverquot; />
<asp:Button OnClick=quot;submitquot; Text=quot;Submitquot; runat=quot;serverquot; />
<p><asp:Label id=quot;lbl1quot; runat=quot;serverquot; /></p>
</form>
</body>
</html>
Asp.Net Forms1

Contenu connexe

Dernier

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
#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
 
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
 

Dernier (20)

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
#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
 
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...
 

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Asp.Net Forms1

  • 1. ASP.NET Web Forms All server controls must appear within a <form> tag, and the <form> tag must contain the runat=quot;serverquot; attribute. ASP.NET Web Forms All server controls must appear within a <form> tag, and the <form> tag must contain the runat=quot;serverquot; attribute. The runat=quot;serverquot; attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts: <form runat=quot;serverquot;> ...HTML + server controls </form> Note: The form is always submitted to the page itself. If you specify an action attribute, it is ignored. If you omit the method attribute, it will be set to method=quot;postquot; by default. Also, if you do not specify the name and id attributes, they are automatically assigned by ASP.NET. Note: An .aspx page can only contain ONE <form runat=quot;serverquot;> control! If you select view source in an .aspx page containing a form with no name, method, action, or id attribute specified, you will see that ASP.NET has added these attributes to the form. It looks something like this: <form name=quot;_ctl0quot; method=quot;postquot; action=quot;page.aspxquot; id=quot;_ctl0quot;> ...some code </form> Submitting a Form A form is most often submitted by clicking on a button. The Button server control in ASP.NET has the following format: <asp:Button id=quot;idquot; text=quot;labelquot; OnClick=quot;subquot; runat=quot;serverquot; /> The id attribute defines a unique name for the button and the text attribute assigns a label to the button. The onClick event handler specifies a named subroutine to execute. In the following example we declare a Button control in an .aspx file. A button click runs a subroutine which changes the text on the button: ASP .NET Maintaining the ViewState
  • 2. You may save a lot of coding by maintaining the ViewState of the objects in your Web Form. Maintaining the ViewState When a form is submitted in classic ASP, all form values are cleared. Suppose you have submitted a form with a lot of information and the server comes back with an error. You will have to go back to the form and correct the information. You click the back button, and what happens.......ALL form values are CLEARED, and you will have to start all over again! The site did not maintain your ViewState. When a form is submitted in ASP .NET, the form reappears in the browser window together with all form values. How come? This is because ASP .NET maintains your ViewState. The ViewState indicates the status of the page when submitted to the server. The status is defined through a hidden field placed on each page with a <form runat=quot;serverquot;> control. The source could look something like this: <form name=quot;_ctl0quot; method=quot;postquot; action=quot;page.aspxquot; id=quot;_ctl0quot;> <input type=quot;hiddenquot; name=quot;__VIEWSTATEquot; value=quot;dDwtNTI0ODU5MDE1Ozs+ZBCF2ryjMpeVgUrY2eTj79HNl4Q=quot; /> .....some code </form> Maintaining the ViewState is the default setting for ASP.NET Web Forms. If you want to NOT maintain the ViewState, include the directive <%@ Page EnableViewState=quot;falsequot; %> at the top of an .aspx page or add the attribute EnableViewState=quot;falsequot; to any control. Look at the following .aspx file. It demonstrates the quot;oldquot; way to do it. When you click on the submit button, the form value will disappear: <html> <body> <form action=quot;demo_classicasp.aspxquot; method=quot;postquot;> Your name: <input type=quot;textquot; name=quot;fnamequot; size=quot;20quot;> <input type=quot;submitquot; value=quot;Submitquot;> </form> <% dim fname fname=Request.Form(quot;fnamequot;) If fname<>quot;quot; Then Response.Write(quot;Hello quot; & fname & quot;!quot;) End If %> </body> </html> Example Here is the new ASP .NET way. When you click on the submit button, the form value will NOT disappear: <script runat=quot;serverquot;> Sub submit(sender As Object, e As EventArgs) lbl1.Text=quot;Hello quot; & txt1.Text & quot;!quot; End Sub </script>
  • 3. <html> <body> <form runat=quot;serverquot;> Your name: <asp:TextBox id=quot;txt1quot; runat=quot;serverquot; /> <asp:Button OnClick=quot;submitquot; Text=quot;Submitquot; runat=quot;serverquot; /> <p><asp:Label id=quot;lbl1quot; runat=quot;serverquot; /></p> </form> </body> </html> ASP .NET - The TextBox Control The TextBox control is used to create a text box where the user can input text. The TextBox Control The TextBox control is used to create a text box where the user can input text. The TextBox control's attributes and properties are listed in our web controls reference page. The example below demonstrates some of the attributes you may use with the TextBox control: Example <html> <body> <form runat=quot;serverquot;> A basic TextBox: <asp:TextBox id=quot;tb1quot; runat=quot;serverquot; /> <br /><br /> A password TextBox: <asp:TextBox id=quot;tb2quot; TextMode=quot;passwordquot; runat=quot;serverquot; /> <br /><br /> A TextBox with text: <asp:TextBox id=quot;tb4quot; Text=quot;Hello World!quot; runat=quot;serverquot; /> <br /><br /> A multiline TextBox: <asp:TextBox id=quot;tb3quot; TextMode=quot;multilinequot; runat=quot;serverquot; /> <br /><br /> A TextBox with height: <asp:TextBox id=quot;tb6quot; rows=quot;5quot; TextMode=quot;multilinequot; runat=quot;serverquot; /> <br /><br /> A TextBox with width: <asp:TextBox id=quot;tb5quot; columns=quot;30quot; runat=quot;serverquot; />
  • 4. </form> </body> </html> Add a Script The contents and settings of a TextBox control may be changed by server scripts when a form is submitted. A form can be submitted by clicking on a button or when a user changes the value in the TextBox control. In the following example we declare one TextBox control, one Button control, and one Label control in an .aspx file. When the submit button is triggered, the submit subroutine is executed. The submit subroutine writes a text to the Label control: <script runat=quot;serverquot;> Sub submit(sender As Object, e As EventArgs) lbl1.Text=quot;Your name is quot; & txt1.Text End Sub </script> <html> <body> <form runat=quot;serverquot;> Enter your name: <asp:TextBox id=quot;txt1quot; runat=quot;serverquot; /> <asp:Button OnClick=quot;submitquot; Text=quot;Submitquot; runat=quot;serverquot; /> <p><asp:Label id=quot;lbl1quot; runat=quot;serverquot; /></p> </form> </body> </html> Example In the following example we declare one TextBox control and one Label control in an .aspx file. When you change the value in the TextBox and either click outside the TextBox or press the Tab key, the change subroutine is executed. The submit subroutine writes a text to the Label control: <script runat=quot;serverquot;> Sub change(sender As Object, e As EventArgs) lbl1.Text=quot;You changed text to quot; & txt1.Text End Sub </script> <html> <body> <form runat=quot;serverquot;> Enter your name: <asp:TextBox id=quot;txt1quot; runat=quot;serverquot; text=quot;Hello World!quot; ontextchanged=quot;changequot; autopostback=quot;truequot;/> <p><asp:Label id=quot;lbl1quot; runat=quot;serverquot; /></p> </form> </body> </html>
  • 5. ASP.NET - The Button Control The Button control is used to display a push button. The Button Control The Button control is used to display a push button. The push button may be a submit button or a command button. By default, this control is a submit button. A submit button does not have a command name and it posts the page back to the server when it is clicked. It is possible to write an event handler to control the actions performed when the submit button is clicked. A command button has a command name and allows you to create multiple Button controls on a page. It is possible to write an event handler to control the actions performed when the command button is clicked. The Button control's attributes and properties are listed in our web controls reference page. The example below demonstrates a simple Button control: <html> <body> <form runat=quot;serverquot;> <asp:Button id=quot;b1quot; Text=quot;Submitquot; runat=quot;serverquot; /> </form> </body> </html> Add a Script A form is most often submitted by clicking on a button. In the following example we declare one TextBox control, one Button control, and one Label control in an .aspx file. When the submit button is triggered, the submit subroutine is executed. The submit subroutine writes a text to the Label control: <script runat=quot;serverquot;> Sub submit(sender As Object, e As EventArgs) lbl1.Text=quot;Your name is quot; & txt1.Text End Sub </script> <html> <body> <form runat=quot;serverquot;> Enter your name: <asp:TextBox id=quot;txt1quot; runat=quot;serverquot; /> <asp:Button OnClick=quot;submitquot; Text=quot;Submitquot; runat=quot;serverquot; /> <p><asp:Label id=quot;lbl1quot; runat=quot;serverquot; /></p> </form> </body> </html>