net training in gandhinagar module-7

27
.Net training In gandhin agar http://shreedhoon.com/training/aspNetTraining.php . 1 01/30/22

Upload: jay-chaudhari

Post on 06-Apr-2016

214 views

Category:

Documents


2 download

DESCRIPTION

We are an IT Company that's develop website,software,android,iPhone application as well as provide professional training in different course like php training, android training, iPhone training, .net training in Gandhinagar. .NET Training in Gandhinagar ,php training in gandhinagar

TRANSCRIPT

Page 1: Net Training in Gandhinagar Module-7

.Net training In gandhinagar

http://shreedhoon.com/training/aspNetTraining.php.

104/26/23

Page 2: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 2

C#/.NET

Basics 2Some code is from “C# in a

Nutshell” and “Programming C#”

04/26/23

.net training in gandhinagar

Page 3: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 3

This week

• Event Handling and delegates• ASP.NET Web Forms• ASP.NET Web Services

04/26/23

Page 4: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 4

Event Handling Model

• Delegates listen for the events and call registered handlers

• Each component has a delegate for every event it can raise

• We register a method with the delegate and the delegate will call the method asynchronously

04/26/23

Page 5: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 5

Delegates (1)

• A Button, for example, needs to notify some object when it is pushed

• We don’t want to hardwire (in the button) which object to call

• A delegate is a reference type used to encapsulate a method with particular parameter types

04/26/23

Page 6: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 6

Delegate (2)using System;delegate String Foo(String x); // create a delegate class

class Test {

public static void Main() { Foo f = new Foo(ConvertToUpperCase); // create a delegate object String answer = f("abcd"); // call the method in the // object Console.WriteLine(answer); } public static String ConvertToUpperCase(String s) { return s.ToUpper(); }}

04/26/23

Page 7: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 7

Delegate (3)public class Form1 : System.Windows.Forms.Form {

private System.Windows.Forms.Button multiplyButton;

public void foo() { this.multiplyButton = new System.Windows.Forms.Button(); this.multiplyButton.Text = "Multiply";

this.multiplyButton.Click += new System.EventHandler(this.multiplyButton_Click); } private void multiplyButton_Click(object sender, System.EventArgs e)

{textBox3.Clear();string op1Str = op1.Text;string op2Str = op2.Text;

: }

Delegate reference

Delegate

Encapsulatedmethod

04/26/23

Page 8: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 8

Multicast Delegateusing System; // From C# In A Nutshelldelegate void MethodInvoker(); // define delegate class class Test { static void Main() { // create a Test object // and call its constructor new Test(); }

04/26/23

Page 9: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 9

Test() {

MethodInvoker m = null; m += new MethodInvoker(Foo); // overloaded += m += new MethodInvoker(Goo); // delegate holds m(); // pointers to two } // methods

m

MethodInvokervoid Foo()

void Goo()

04/26/23

Page 10: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 10

void Foo() { Console.WriteLine("Foo"); } void Goo() { Console.WriteLine("Goo"); }}

Output:FooGoo

04/26/23

Page 11: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 11

ASP.NET Web Forms (1)

• Web Forms bring rapid appplication development to the web

• Similar technology is available on J2EE platforms (struts, Java Server Faces)

• Drag and drop development for the web tier – write event handlers as in Windows

Forms• User interacts with the sever via a

standard browser04/26/23

Page 12: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 12

ASP.NET Web Forms (2)

• Web pages are dynamically generated• Standard HTML is sent to the browser• Notepad would work but Visual Studio

makes life easy• The user interface code is in an .aspx file• The logic (C# code) is stored in a separate

file (containing event handling code)• Every .aspx file has this “code-behind” file04/26/23

Page 13: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 13

ASP.NET Web Forms (3)

• Postback events are handled on the server with an HTTP request. For example, the submit button is clicked.

• Non-postback events are not handled by the server immediately. For example, text is entered into a form or the mouse is moved.

• State is automatically added to an otherwise stateless protocol. .NET maintains the user’s session.

04/26/23

Page 14: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 14

Web Form Life Cycle

• Complicated series of activities similar to what is found in J2EE struts and JSF

• For this class let’s just say that a lot of pre- and post-processing goes on for each web request

04/26/23

Page 15: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 15

Creating A Web Form(1)

• Prerequisites: IIS and Front Page Server Extensions (use Internet Service Manager and right click on the web site/All Tasks/Configure Server Extensions)

• Start/Microsoft Visual Studio .NET/ New Project/Visual C#/ASP.NET Web Application/BinomialTreeWebApp

• Generated code goes into c:\Inetpub\wwwroot\BinomialTreeWebApp

04/26/23

Page 16: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 16

Creating A Web Form(2)

• Two files generated - The .aspx file holds the HTML - The aspx.cs file holds the C#• To see the C# code right click the form

and select view code• Note that you can see the design view or

the HTML view (tabs on bottom)

04/26/23

Page 17: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 17

Web Form Step-by-step(1)(1) Start with a simple C# program – Divider.csusing System;

public class Divider {

public int divide(int a, int b) { return a / b; } public static void Main(String[] args) {

Divider s = new Divider(); Console.WriteLine(s.divide(10,5)); }}

04/26/23

Page 18: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 18

Web Form Step-by-step(2)

(2) Compile to a .dll csc –t:library Divider.cs

(3) Run .NET New Project choose C# select .NET Web Application enter location: http://localhost/ADivider

04/26/23

Page 19: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 19

Web Form Step-by-step(3)

(4) Paint the screen in design mode(5) Right click to get to backing code(6) Add a reference to the .dll with

Project/Add Reference(7) Use the class

04/26/23

Page 20: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 20

Web Services

“The internet is evolving from a collection of isolated web sites and applications into a general communication bus for distributed applications.”

Pradeep Tapadiya, author of “.NET Programming”

04/26/23

Page 21: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 21

ASP.NET Web Services(1)

0) Check if IIS is running by attempting to visit http://localhost

1) If it's not running click Start/Settings/Control Panel/Add Remove Programs/ Add Remove Windows Components and enable IIS.2) If .NET was installed after IIS reconfigure IIS by

running aspnet_regiis.exe /i from a command prompt.

04/26/23

Page 22: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 22

ASP.NET Web Services(2)(1) Start with a simple C# program – Divider.csusing System;

public class Divider {

public int divide(int a, int b) { return a / b; } public static void Main(String[] args) {

Divider s = new Divider(); Console.WriteLine(s.divide(10,5)); }}

04/26/23

Page 23: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 23

ASP.NET Web Services(3)

(2) Compile to a .dll csc –t:library Divider.cs

(3) Run .NET New Project choose C# select ASP .NET Web Service enter location: http://localhost/ADividerWS

04/26/23

Page 24: Net Training in Gandhinagar Module-7

http://shreedhoon.com/training/aspNetTraining.php 24

ASP.NET Web Services(4)

(4) Add a reference to the .dll with Project/Add Reference

(5) Edit the web service sample so that it provides the correct signature and calls

the divide method(6) Get the WSDL document from a browser(7) Run wsdl, compile the result, and write a

client04/26/23

Page 25: Net Training in Gandhinagar Module-7

.net training in gandhinagar

04/26/23 http://shreedhoon.com/training/aspNetTraining.php 25

Page 26: Net Training in Gandhinagar Module-7

For more visit

04/26/23 http://shreedhoon.com/training/aspNetTraining.php 26

• Website :• www.shreedhoon.com• Blogs:• http://dotnettrainingingandhinagar.blogspot.in/• http://dotnettrainingingandhinagar.tumblr.com/• http://shreedhoontraining.weebly.com/• http://shreedhoontraining.weebly.com/about.html

Page 27: Net Training in Gandhinagar Module-7

Thank you for visiting

04/26/23 http://shreedhoon.com/training/aspNetTraining.php 27