(ASP课件)第三章Web服务器控.ppt_第1页
(ASP课件)第三章Web服务器控.ppt_第2页
(ASP课件)第三章Web服务器控.ppt_第3页
(ASP课件)第三章Web服务器控.ppt_第4页
(ASP课件)第三章Web服务器控.ppt_第5页
已阅读5页,还剩36页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第三章,Web服务器控件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,2,回顾,ASP.NET页文件是含有将在Web服务器上执行代码的文件。其扩展名是.aspx或.ascxASP.NET页面中使用两种类型的脚本:服务器端脚本客户端脚本事件处理程序实际上就是一个子程序,执行任何给定事件的相关代码在页面加载时引发Page_Load事件Page.IsPostback属性用于检查页面是否为首次加载ViewState是ASP.NET中用来保存WEB控件回传时状态值的页面隐藏控件ASP.NET代码隐藏文件使开发人员可以在C#或VisualBasic.NET类中编写控制它们的页的逻辑,这样可与HTML代码清楚地分离开来,2007iSoftStoneHoldingsLtd.AllRightsReserved.,3,目标,使用文本输入控件使用控制权转移控件使用选择控件讨论其他控件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,4,Web控件简介,控件是用于在Web窗体执行所有任务的工具控件定义Web窗体的外观MicrosoftVisualStudio.NET提供了两种可用于Web窗体的控件,分别为:Web服务器控件HTML控件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,5,添加Web服务器控件,使用Web窗体设计器添加Web服务器控件:,Web服务器控件面板,双击或单击并拖动Web服务器控件,将其添加到Web窗体,2007iSoftStoneHoldingsLtd.AllRightsReserved.,6,Web服务器控件的类型,内部控件文本输入控件控制权转移控件选择控件容器控件其他控件用于某些特定用途的专用控件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,7,文本输入控件,TextBox控件用作将由用户或程序员输入的文本的占位符,输入的文本可以用程序读取Label标签-用作将由程序员在设计时或运行时输入的文本的占位符。在此控件内不能进行用户交互,有两种类型的文本输入控件:,2007iSoftStoneHoldingsLtd.AllRightsReserved.,8,Label和TextBox的属性和事件,Label的属性:,TextChanged事件用户输入信息后离开TextBoxWeb服务器控件时,控件引发程序员可以处理的此事件。,2007iSoftStoneHoldingsLtd.AllRightsReserved.,9,使用文本输入控件,privatevoidtxtUserName_TextChanged(objectsender,System.EventArgse)lblUserNm.Text=txtUserName.Text;,Label控件,文本属性,TextBox控件,文本属性,2007iSoftStoneHoldingsLtd.AllRightsReserved.,10,控制权转移控件,有四种类型的控制权转移控件:,Button控件显示标准HTML窗体按钮ImageButton控件-显示图像窗体按钮LinkButton控件-在按钮上显示超文本链接Hyperlink控件-在某些文本上显示超文本链接,2007iSoftStoneHoldingsLtd.AllRightsReserved.,11,Button的属性和事件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,12,ImageButton的属性和事件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,13,LinkButton的属性和事件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,14,超链接属性,注意:此控件没有公开事件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,15,使用控制权转移控件,处理ImageButton的Click事件,privatevoidbtnTenNews_Click(objectsender,System.EventArgse)/处理按钮Click事件lblStatus.Text=已单击按钮!;privatevoidimgBtnSoccer_Click(objectsender,System.Web.UI.ImageClickEventArgse)/处理按钮Click事件lblStatus.Text=已单击图像按钮!;,处理Button的Click事件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,16,使用控制权转移控件,Button控件,ImageButton控件,Hyperlink控件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,17,选择控件,有四种类型的选择控件:,CheckBox为用户提供一种方法在true/false、yes/no或on/off选项之间切换RadioButton-用于只从选项列表中选择一个选项DropdownList-允许用户从预定义列表中选择一项ListBox-允许用户从预定义列表中选择一项或多项,2007iSoftStoneHoldingsLtd.AllRightsReserved.,18,Checkbox:属性和事件,CheckedChanged事件-当Checked属性值在发布到服务器的各个操作之间发生变化时发生,2007iSoftStoneHoldingsLtd.AllRightsReserved.,19,RadioButton:属性和事件,CheckedChanged事件-当Checked属性值在发布到服务器的各个操作之间发生变化时发生,2007iSoftStoneHoldingsLtd.AllRightsReserved.,20,DropdownList属性,2007iSoftStoneHoldingsLtd.AllRightsReserved.,21,DropdownList事件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,22,ListBox:属性和事件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,23,使用选择控件,privatevoidradGenderM_CheckedChanged(objectsender,System.EventArgse)strGender=“男;privatevoidcboSalRange_SelectedIndexChanged(objectsender,System.EventArgse)strSalRange=cboSalRange.SelectedItem.Text;privatevoidchkMusic_CheckedChanged(objectsender,System.EventArgse)if(strHobbies=)strHobbies=strHobbies+chkMusic.Text;elsestrHobbies=strHobbies+,+chkMusic.Text;privatevoidlstOwnership_SelectedIndexChanged(objectsender,System.EventArgse)if(strOwnership=)strOwnership=strOwnership+lstOwnership.SelectedValue;elsestrOwnership=strOwnership+,+lstOwnership.SelectedValue;,显示处理Checkbox/RadioButton/DropdownList/List控件的代码片段,2007iSoftStoneHoldingsLtd.AllRightsReserved.,24,使用选择控件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,25,容器控件,有两种类型的容器控件:,Panel控件PanelWeb服务器控件提供一个位于Web窗体页的容器控件,该控件可用作静态文本和其他控件的父级Placeholder控件-存储动态添加到网页上的服务器控件的容器,2007iSoftStoneHoldingsLtd.AllRightsReserved.,26,Placeholder:属性和事件,属性:最常用属性是用于添加/删除此容器控件的子控件的Controls属性,事件:所有的事件都继承自System.Web.UI.WebControls.WebControl类通常不处理此控件的事件,子控件的特定事件按照控件的方式进行处理,2007iSoftStoneHoldingsLtd.AllRightsReserved.,27,privatevoidbtnAdd_Click(objectsender,System.EventArgse)PanelpnPerson=newPanel();switch(nNumber%3)case1:pnPerson.BackColor=Color.Red;break;case2:pnPerson.BackColor=Color.Green;break;default:pnPerson.BackColor=Color.Blue;break;TabletbTemp=newTable();/添加姓名TableRowobjRow=newTableRow();TableCelltcLblName=newTableCell();tcLblName.Text=姓名;objRow.Cells.Add(tcLblName);TableCelltcTxtName=newTableCell();TextBoxtxtObjName=newTextBox();,2007iSoftStoneHoldingsLtd.AllRightsReserved.,28,txtObjName.Text=this.txtName.Text;tcTxtName.Controls.Add(txtObjName);objRow.Cells.Add(tcTxtName);TableCelltcLblSex=newTableCell();tcLblSex.Text=性别;objRow.Cells.Add(tcLblSex);TableCelltcTxtSex=newTableCell();TextBoxtxtObjSex=newTextBox();for(inti=0;i=this.rdlSex.Items.Count-1;i+)if(this.rdlSex.Itemsi.Selected=true)txtObjSex.Text=this.rdlSex.Itemsi.Text;tcTxtSex.Controls.Add(txtObjSex);objRow.Cells.Add(tcTxtSex);tbTemp.Rows.Add(objRow);/添加第二行TableRowobjRow2=newTableRow();TableCelltcLblNum=newTableCell();tcLblNum.Text=学号;,2007iSoftStoneHoldingsLtd.AllRightsReserved.,29,objRow2.Cells.Add(tcLblNum);TableCelltcTxtNum=newTableCell();tcTxtNum.Text=this.txtNumber.Text;objRow2.Cells.Add(tcTxtNum);TableCelltcLblHobby=newTableCell();tcLblHobby.Text=爱好;objRow2.Cells.Add(tcLblHobby);TableCelltcTxtHobby=newTableCell();foreach(ListItemliinthis.cklHobby.Items)if(li.Selected=true)tcTxtHobby.Text+=li.Text+,;objRow2.Cells.Add(tcTxtHobby);tbTemp.Rows.Add(objRow2);pnPerson.Controls.Add(tbTemp);this.phControls.Controls.Add(pnPerson);nNumber+=1;,2007iSoftStoneHoldingsLtd.AllRightsReserved.,30,使用容器控件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,31,其他控件,AdRotator用于显示横幅广告集合中的随机选择内容,该集合在基于XML的广告文件中指定Calendar-允许开发人员提供基于日历的界面,用于选择日期或查看与日期相关的数据,其他控件是用于特定用途的控件,只能用于特殊任务,2007iSoftStoneHoldingsLtd.AllRightsReserved.,32,AdRotator:属性和事件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,33,AdRotator调用的XML文件广告,2007iSoftStoneHoldingsLtd.AllRightsReserved.,34,使用AdRotator控件3-1,注意:添加AdRotator控件之后,右击“项目”,“添加新项”,然后选择如图所示的“XML文件”,从而创建包含广告图像的XML文件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,35,使用AdRotator控件3-2,新建XML文件之后,将以下XML代码添加到此文件中:,images/Bluehills.gif冬日站点60Usersimages/Sunset.gif夏日站点80Developers,指定广告属性的XML代码,2007iSoftStoneHoldingsLtd.AllRightsReserved.,36,使用AdRotator控件3-3,2007iSoftStoneHoldingsLtd.AllRightsReserved.,37,Calendar:属性和事件,2007iSoftStoneHoldingsLtd.AllRightsReserved.,38,使用Calendar控件3-1,2007iSoftStoneHoldingsLtd.AllRightsReserved.,39,privatevoidbtnStart_Click(objectsender,System.EventArgse)this.hdTemp.Value=Start;calStEndDt.StyleLEFT=(int.Parse(btnStart.StyleLEFT.Substring(0,bt

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论