.


:




:

































 

 

 

 


1. ASP.Net. .




Ͳ Dz

 

 

㳿

(4 7 )

6.050103

 

㳿 6.050103 / . . , . . // : , 2016. 88 .

 

: ..., . ..

..., . ..

 

 

( 1 29 2016 .)

 

㳿, - 㳿 ASP.Net.

̲

1. ..............................................................................................................4

2. Ͳ .................................................................................5

2.1. 1. ASP.Net. .............................................................................................................5

2.2. 2. MasterPage, UserController 󅅅..27

2.3. 3. . 㳿 ADO.net ..47

2.4. 4. DataSet SqlDataSource.68

2.5. 5. -ⅅ...78

3. ˲............................................................87

 

 


㳿 6.050103 . 4 7 .

(), , , ; . , # 㳿 ASP.NET.

.

:

- , , ;

- , ;

- , ;

- ;

- , , #, 㳿 ASP.NET.

#, 㳿 ASP.NET:

-

-

-

- , , , .

-

- ;

- , .

Ͳ

:

- ;

- # 㳿 ASP.Net;

- ;

- .

 

1. ASP.Net. .

: , . HTML. - , , . ASP.NET , . , . -.

1. - ASP.Net. ASP.NET File ð New ð Web Site. , New ð Project , - . , New Web Site (. 1.1) :

- (Templates) , Web-. ϳ ASP.NET Web- Web-. . Web Web-, Web- Web-. г , Visual Studio . Web- Web-, Web- Web-. , . ;

- (Location) Web-. File System ( ). HTTP FTP ;

- (Language) .NET, Web-.

 

. 1.1. ³ Web

(Browse), (Choose Location . 1.1).

ϳ Web- , Visual Studio Web-. Web- , default.aspx, . 1.2.

 

. 1.2. -

, HTML , , ASP.NET. .

<%@ Page Language="C#" %>. <% ASP-. Page aspx. Language , C#, VB, C++ J#. CodeFile (code-behind). Inherits , , .

Default.aspx.cs.

<form runat="server">

. , runat, "server" ( ). , . , . ֳ HTML form, <asp: />. , Button, :

<asp:Button ID="Button1" runat="server" Text="Button" />.

, asp , , .NET Framework, ID , , , .

. 1.3 -, . , HTML , form, button. , , .

 

. 1.3. Web-

 

(. 1. 4).

 

. 1. 4. ³ Web-

 

, , , . ϳ , , . , 䳿 Page_Load. , Toolbox , (. 1.5).

 

. 1. 5. Toolbox

2. Web-.Web- HTML- drag-and-drop, Windows-, . Design Source, .

, . - . HTML, . IntelliSense, Visual Studio HTML, .

, , . . Default.aspx . :

1. Toolbox , . , .aspx , Toolbox . , , . 1. 6.

 

. 1. 6.

 

2. Toolbox , . .aspx , Toolbox - . 1. 7.

 

. 1.7.

 

Design Source - . - , HTML . , .aspx HTML . , -, Windows-. - , , . , . , . 1. 8.

 

. 1. 8. , -

 

䳿 . 䳿 , , (Properties) ( Properties ) ( ) 䳿, , Click (.1. 9).

 

. 1. 9. ³ Button

Button1_Click, 䳺 Click Button. Default.aspx.cs. , . Response, , 볺. 䳿 .

 

Response.Write(" ASP.NET");

 

³ (. 1. 10).

 

. 1. 10. ³ 䳿 Button1

 

. F5 . - ( F5 Debug ð Start Debugging), , . 1. 11.

 

. 1. 11. ij

ϳ -, Visual Studio. (. 1. 12), - , .

 

. 1. 12. -

 

-, , (. 1. 13).

 

. 1. 13. -, Internet Explorer

 

, . . ASP.NET (. 1. 14).

 

. 1. 14. Button

 

ᒺ Response. ᒺ , , , Windows- .

ᒺ Label, , , . Label. Text ( , ). (. 1. 15).

 

. 1. 15. ³ Label.

䳿 Button1_Click . Response.Write(" ASP.NET"), :

 

Label1.Text = " ASP.NET";

 

ϳ , , , , , , :

 

<span id="Label1"> ASP.NET</span><br />

 

Label.

3. , , , .

. TextBox, 볿 Label , . 1. 16.

 

. 1. 16. ³

 

, , , . 䳿 , lbl_Result , 볿 , . , , . 䳿 Button1_Click :

 

lbl_Result.Text = ", "+tb_FirstName.Text+" "+ tb_LastName.Text+"! ASP.NET";

lbl_Result.ForeColor = Color.Red;

 

(. 1.17)

 

. 1. 17. ,

 

Visual Studio , (. 1. 18).

. 1. 18.

, , , (. 1. 19).

 

. 1. 19. ,

(namespace), Color. Drawing System. Default.aspx.cs :

 

using System.Drawing;

 

. . , (. 1.20).

 

. 1. 20. Web-

 

4. Label. . (. 1. 21).

 

<html xmlns=""http://www.w3.org/1999/xhtml""><head> <title> </title></head><body> <center> <h2> </h2> <br /> <form id="frmDemo" runat="server"><asp:Label ID="ShopNews" runat="server" Font-Size="20" ForeColor= "red" BackColor="lightgray" BorderWidth="4" BorderStyle="groove" Height="50" Width="500" Text=" " /> </form> </center></body></html>

. 1. 21.

 

Label, . , , .

protected void Page_Load(object sender, EventArgs e)

{

Label ShopNews = new Label();

ShopNews.Text = " ";

ShopNews.Font.Size = 20;

ShopNews.ForeColor = Color.Red;

ShopNews.BackColor = Color.LightGray;

ShopNews.BorderWidth = 4;

ShopNews.BorderStyle = BorderStyle.Groove;

ShopNews.Height = 50;

ShopNews.Width = 500;

form1.Controls.Add(ShopNews);

}

form1 ID form.

 

5. (. 1. 22).

 


. 1. 22.

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title> </title>

</head>

<body>

<form id="form1" runat="server">

<div style="text-align:left">

<table>

<tr>

<td style="width:100"> </td>

<td style="width:100"> <asp:TextBox ID="txt1" runat="server" /> </td>

</tr>

<tr>

<td style="width:100"> </td>

<td style="width:100"> <asp:TextBox ID="txt2" runat="server" TextMode="MultiLine" Rows="5" Wrap="true"/> </td>

</tr>

<tr>

<td style="width:100"> </td>

<td style="width:100"> <asp:TextBox ID="txt3" runat="server" TextMode="Password"/> </td>

</tr>

</table>

</div>

<br />

<asp:Button ID="input" runat="server" Text="" onclick="input_Click" /> <br/>

</form>

<br/>

<asp:Label ID="l1" runat="server" /> <br />

<asp:Label ID="l2" runat="server" /> <br />

<asp:Label ID="l3" runat="server" /> <br />

<asp:Label ID="L4" runat="server" /> <br />

</body>

</html>

 

. , . Page.IsPostBack , true, 볺, false.

protected void Page_Load(object sender, EventArgs e)

{

if (Page.IsPostBack)

{

if (txt1.Text!= "") l1.Text = " :" + txt1.Text;

if (txt2.Text!= "") l2.Text = " :" + txt2.Text;

if (txt3.Text!= "") l3.Text = " :" + txt3.Text;

}

}

protected void input_Click(object sender, EventArgs e)

{

double i;

i= (Convert.ToInt32(txt1.Text) + Convert.ToInt32(txt2.Text)*0.1)/Convert.ToInt32(txt3.Text);

L4.Text =" = " +i.ToString();

}

 

6. . . 1. 23. . 1. 24.

 

. 1. 23.

 

. 1. 24.

 

:

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title> </title>

</head>

<body>

<br /><br /> <asp:label runat="server" ID="Question" Font-

Bold="True" Font-Size="Large" ForeColor="#0000C0"> </asp:label>

<br /><br />

<form id="v" runat="server">

<asp:RadioButtonList id="radVoting" runat="server" >

<asp:ListItem value=" " />

<asp:ListItem value=" " />

<asp:ListItem value=" (), " />

<asp:ListItem value=" " />

</asp:RadioButtonList>

<input type="Submit" value="!" >

<br /><br />

</form>

<asp:Label id="Message" runat="server" />

</body>

</html>

 

䳿 :

protected void Page_Load(object sender, EventArgs e)

{

if (Page.IsPostBack)

{

if(radVoting.SelectedItem==null) Message.Text = " ";

else

{

Message.Text = " . : " + radVoting.SelectedItem.Value;

v.Visible = false;

}

} }

 

7. DropDownList. , , . (. 1.25).



. 1. 25.

.

protected void Page_Load(object sender, EventArgs e)

{

if (Page.IsPostBack) l1.Text = " " + Category.SelectedItem.Value;

}

:

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<br> <br />

<asp:DropDownList ID="Category" runat="server">

<asp:ListItem> </asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem> </asp:ListItem>

<asp:ListItem Selected="true"> </asp:ListItem>

<asp:ListItem> -</asp:ListItem>

</asp:DropDownList>

<input type="Submit">

<br />

<asp:Label ID="lblMessage" runat="server" />

</div>

</form>

<asp:Label ID="l1" runat="server"></asp:Label>

</body>

</html>

 

DropDownList , , Page_Load:

 

DropDownList Category = new DropDownList(); Category.Items.Add(""); Category.Items.Add(""); Category.Items.Add(""); ListItem selItem = new ListItem("", ""); Category.Items.Add(selItem); Category.Items.Add(new ListItem("-")); Category.SelectedIndex = 3; form1.Controls.Add(Category);

 

8. ListBox (. 1. 26).

 


 


. 1. 26.

 

:

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<br> ?<br />

<form id="form1" runat="server">

<div>

<asp:ListBox ID="cities" runat="server" SelectionMode="multiple">

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

<asp:ListItem></asp:ListItem>

</asp:ListBox><br />

<input type="Submit">

<p>

<asp:Label ID="Message" runat="server" /><br />

</div>

</form>

</body>

</html>

䳿 :

protected void Page_Load(object sender, EventArgs e)

{

string msgCitiesList = "";

if (Page.IsPostBack)

foreach (ListItem it in cities.Items)

if (it.Selected)

{ msgCitiesList = msgCitiesList + it.Text + "<br />"; }

if (msgCitiesList!= "")

{Message.Text = " : <br />" + msgCitiesList; }

else

{ Message.Text = ""; } }


9. ( 10). (. 1. 27).

 



. 1. 27.

 

:

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form runat="server" id="Experience">

<asp:Label ID="Label1" runat="server" text="

" />

<asp:Panel id="places" runat="server">

<asp:TextBox id="first" runat="server" />

<br />

<br />

</asp:Panel>

<asp:Button id="Add" Text="" OnCommand="AddExperience" CommandName="Add" runat="server" />

</form>

</body>

</html> , : void AddExperience(Object sender, EventArgs e){ if (num < 10) { TextBox newBox = new TextBox(); newBox.ID = "box" + num; tb[num] = newBox; num++; } for (int i=0; i<10; i++) // . { if (tb[i]!= null) { places.Controls.Add(tb[i]); Label lb=new Label(); lb.Text="<br><br>"; places.Controls.Add(lb); } else break; }}

 

10. - image. images ( 10) image1, image2 (. 1. 28).

 

 



. 1. 28 -

 

:

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<h3>Image Example</h3>

<asp:Image id="Image1" runat="server"

ImageAlign="top"

AlternateText=" "

height="300"

ImageUrl="images/1.jpg"/>

<hr>

<br><br>

<asp:Button id="Next"

Text="Next"

OnClick="NextImage"

runat="server" CommandName="NextImage"/>

<br><br>

</form>

</body>

</html>

䳿 Next:

public partial class _Default: System.Web.UI.Page

{

public static int count = 1;

protected void Page_Load(object sender, EventArgs e)

{ }

protected void NextImage(object sender, EventArgs e)

{

count++;

if (count == 10) count = 1; //

Image1.ImageUrl = "images/image"+count + ".jpg";

}

}

11. ³ -. (. 1. 29).

:

<asp:Calendar ID="calVoyage" runat="server" BackColor="lightgreen" CellPadding="3" CellSpacing="3" NextPrevFormat="FullMonth" SelectionMode="DayWeekMonth " OnSelectionChanged="calSelectChange" />

<asp:Label ID="TextToUser" runat="server" Font-Bold="True" Font-Underline="False" /><br>

<p>

<asp:Label ID="Message" runat="server" /><br />

<asp:Label ID="L1" runat="server" /><br />


 

. 1. 29.

 

.

if (Page.IsPostBack)

{

TextToUser.Text = " " + calVoyage.SelectedDate.ToLongDateString();

}

protected void calSelectChange(object sender, EventArgs e)

{

if (calVoyage.SelectedDate > DateTime.Today)

{

TextToUser.Text = " " + calVoyage.SelectedDate.ToShortDateString() + "?";

Button ok = new Button();

ok.Width = 100;

ok.Text = "";

form1.Controls.Add(ok);

}

else

TextToUser.Text=" ";

}

12. (. 1.30).

 

. 1.30.

:

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:Label ID="Label1" runat="server" Text=""></asp:Label>

<asp:TextBox ID="tb_Name" runat="server"></asp:TextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage=" " ControlToValidate="tb_Name"> </asp:RequiredFieldValidator><br />

<asp:Label ID="Label2" runat="server" Text=". "></asp:Label>

<asp:textbox id="TextBox1" runat="server"></asp:textbox>

<asp:RegularExpressionValidator id="RV1" runat="server" ControlToValidate= "TextBox1" ErrorMessage="Not a valid Email" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>

<br />

<asp:Label ID="Label3" runat="server" Text=" ( 18 70)"> </asp:Label> &nbsp;

<asp:TextBox ID="tb_Age" runat="server"></asp:TextBox>

<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate= "tb_Age" ErrorMessage=" 18 70 " MaximumValue="70" MinimumValue="18" Type="Integer">* </asp:RangeValidator>

<br />

<asp:Label ID="Label4" runat="server" Text=""></asp:Label>

<asp:TextBox ID="tb_Password1" runat="server" TextMode="Password"> </asp:TextBox>

<asp:Label ID="Label5" runat="server" Text=" ()"></asp:Label>

<asp:TextBox ID="tb_Password2" runat="server" TextMode="Password"> </asp:TextBox>

<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="tb_Password1" ControlToValidate="tb_Password2" ErrorMessage= " "></asp:CompareValidator>

<br />

<asp:Label ID="Label6" runat="server" Text=" ( 10)"> </asp:Label>

<asp:TextBox ID="tb_Salary" runat="server"></asp:TextBox>

<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage= " 10" ClientValidationFunction = "SalaryCheck" ControlToValidate="tb_Salary" onservervalidate= "CustomValidator1_ServerValidate"></asp:CustomValidator>

<br />

<asp:Button ID="btn_OK" runat="server" Text="OK" Width="89px" />

</form>

</body>

</html>

 

䳿 :

public partial class _Default: System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{ }

protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)

{ try

{ args.IsValid = int.Parse(args.Value) % 10 == 0; }

catch

{ args.IsValid = false; }

}

}





:


: 2017-02-28; !; : 447 |


:

:

.
==> ...

1581 - | 1557 -


© 2015-2024 lektsii.org - -

: 0.386 .