Properties Changed

Table 28-2: Web Form Controls

Control Type

Properties Changed

Label

Six labels were added: the main caption of the page, Product ID, Product Name, Price, Quantity, and Message, respectively. The ID of the last label was changed to LabelMessage and its text cleared.

TextBox

ID=PID

TextBox

ID=ProductName

TextBox

ID=Price

TextBox

ID=Quantity

Button

ID=Submit Text=Submit

After you design the WebForm, write the code for the Click event of the Submit button. When the user clicks the Submit button, the code of the Click event should do the following:

1. Create an instance of the Web service.

2. Call the AddProduct method of the Web service, passing the values entered by the user on the WebForm as parameters.

3. Display the return value from the AddProduct method in the LabelMessage label.

Following is the code of the Click event of the Submit button that accomplishes the preceding tasks:

Tip To enter code for the Click event of the Submit button, double-click the Submit button in the design view.

private void Submit Click(object sender, System.EventArgs e) {

OSl.Servicel Web1=new OS1.Service1();

LabelMessage.Text=Web1.AddProduct(PID.Text, ProductName.Text, Convert.ToInt32(Price.Text), Convert.ToInt32 (Quantity.Text));

Select Debug ^ Start to run the Web service. The output of the Web application is shown in Figure 28-9.

Fit Id vv- Fiw4l 1Mb IH>

J ' i" > ■" I J---- I - ■ I- J f J J i)£

1 ^in'n.a ^ r : 1 -v^irrtiti'j^.virh i JI|I

j?Le Lrk» m

J

Add a new product

squatty

Unl

_HI

Figure 28-9: This WebForm represents the output of the Web application.

Specify values in the Product ID, Product Name, Price, and Quantity text boxes and click Submit. The Web application adds the required information to the Sales data-base, and a message appears in the LabelMessage label, as shown in Figure 28-10.

FJt Id VV- Ifi-Vi T —H, IH,

mi' j ' i- it"- i> it- - ■ i - j r J

''LJ .' 1 ■ (JJ IP"i ■ n'.r-T^ H' r ■ Jiy.-^-iTh i J1 I ■

{] J Lc 1 - i H

J

Add a new product

?r+ C |=ai?

7";v'ij.L tr,cn | IUI fJaViH

_El

Figure 28-10: You can add a record to the Sales database through the Web application.

0 0

Post a comment