??xml version="1.0" encoding="utf-8" standalone="yes"?>
public SecurityHeader()
{
}
}
2. SecurityHeadercM为webservicecȝ一个属性公开,q在WebMethod里用SecurityHeader
q样允许客户用这个SoapHeader了?BR>public class Map : System.Web.Services.WebService
{
public SecurityHeader keyHeader;
public Map()
{
}
[WebMethod,SoapHeader("keyHeader")]
public string HelloWorld()
{
//q里我们可以获得客户传来的header值按需要做验证{处?BR> string keyValue = keyHeader.key ;
return keyValue;
}
}
客户端用SoapHeader的方法如下(调用之前先声明webreference MapClientQ:
MapService.MapClient.SecurityHeader header = new MapService.MapClient.SecurityHeader();
header.userName = "userName";
header.passWord = "passWord";
header.key = "Hello,this is a key....";
MapClient.Map testClient = new MapService.MapClient.Map();
testClient.SecurityHeaderValue = header;
testClient.Credentials = System.Net.CredentialCache.DefaultCredentials;
string ss = testClient.HelloWorld();
用户控gl承?SPAN lang=EN-US>System.Web.UI.UserControlc?SPAN lang=EN-US>,保存?SPAN lang=EN-US>ascx文g.创徏Ҏ参见: http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpguide/html/cpconwebformsusercontrols.asp
服务器控件承于Controlc?SPAN lang=EN-US>, 保存?SPAN lang=EN-US>CS文g. 创徏Ҏ参见: http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpguide/html/cpconwebformscontroldevelopmentbasics.asp
下表汇M复合控g与用h件之间的差异。有兛_作用h件的详细信息Q请参见 Web H体用户控g?/SPAN>
复合控g |
用户控g |
创作的最短设计时支持?/SPAN> |
创作的完全设计时支持。在可视化设计器中,创作用户控g与创?/SPAN> ASP.NET (“Web H体?/SPAN>)没有差别?/SPAN> |
以目标ؓ公共语言q行库的面向对象的编E语aQ如 C# ?/SPAN> Visual Basic .NETQ是用编E方式创作的?/SPAN> |
使用 ASP.NET 语法和脚本块(或代码隐藏页Q声明性地创作的?/SPAN> 注意 用于创作脚本块的语言是针对公paq行库的面向对象的语aQ如 C#?/SPAN>Visual Basic .NET ?/SPAN> JScript .NETQ但?/SPAN> ASP.NET |架会向开发h员隐藏许多编E细节?/SPAN> |
作ؓE序?/SPAN> (.dll) ~译和保持的?/SPAN> |
另存为带?/SPAN> .ascx 扩展名的文本文gQ带有可选的代码隐藏文gQ?/SPAN> |
非常适于创作一般的可重新发布的控g?/SPAN> |
适合应用E序特定的功能?/SPAN> |
设计时宿M使用时的完全设计时支持。可以将复合控gd到可视化设计器的工具ƈ拖放到页上?/SPAN> |
设计器中的最用支持?/SPAN> |
ASP.NET配置文gWeb.config
《长城在Uѝ?/FONT> 2005-1-19 17:06:04
?WATERSWEA 一、认识Web.config文g Web.config文g是一个XML文本文gQ它用来储存 ASP.NET Web 应用E序的配|信息(如最常用的设|ASP.NET Web 应用E序的n份验证方式)Q它可以出现在应用程序的每一个目录中。当你通过VB.NET新徏一个Web应用E序后,默认情况下会在根目录自动创徏一个默认的 Web.config文gQ包括默认的配置讄Q所有的子目录都l承它的配置讄。如果你想修改子目录的配|设|,你可以在该子目录下新Z个Web.config文g。它可以提供除从父目录承的配置信息以外的配|信息,也可以重写或修改父目录中定义的设|?BR> 在运行时对Web.config文g的修改不需要重启服务就可以生效Q注Q<processModelQ?节例外)。当然Web.config文g是可以扩展的。你可以自定义新配置参数q编写配|节处理E序以对它们q行处理? 二、web.config配置文gQ默认的配置讄Q以下所有的代码都应该位?BR>
?BR>
之间Q出于学习的目的下面的示例都省略了这DXML标记 1、<authenticationQ??BR> 作用Q配|?ASP.NET w䆾验证支持QؓWindows、Forms、PassPort、None四种Q。该元素只能在计机、站Ҏ应用E序U别声明。<authenticationQ?元素必需与<authorizationQ?节配合用?BR> CZQ?BR> 以下CZ为基于窗体(FormsQ的w䆾验证配置站点Q当没有登陆的用戯问需要n份验证的|页Q网自动蟩转到登陆|页?BR>
其中元素loginUrl表示登陆|页的名Uͼname表示Cookie名称 2、<authorizationQ??BR> 作用Q控制对 URL 资源的客L讉KQ如允许匿名用户讉KQ。此元素可以在Q何别(计算机、站炏V应用程序、子目录或页Q上声明。必需与<authenticationQ?节配合用?BR> CZQ以下示例禁止匿名用L讉K
注:你可以用user.identity.name来获取已l过验证的当前的用户名;可以使用 web.Security.FormsAuthentication.RedirectFromLoginPageҎ已验证的用户重定向到用户刚才请求的面.具体的实例请参? Forms验证 http://www.fanvb.net/websample/dataauth.aspx 3、<compilationQ节 作用Q配|?ASP.NET 使用的所有编译设|。默认的debug属性ؓ“True?在程序编译完成交付用之后应其设ؓTrueQWeb.config文g中有详细说明Q此处省略示例) 4、<customErrorsQ? 作用Qؓ ASP.NET 应用E序提供有关自定义错误信息的信息。它不适用?XML Web services 中发生的错误?BR> CZQ当发生错误Ӟ网蟩转到自定义的错误面?BR>
其中元素defaultRedirect表示自定义的错误|页的名U。mode元素表示Q对不在本地 Web 服务器上q行的用hC定义(友好?信息?BR> 5、<httpRuntimeQ节 作用Q配|?ASP.NET HTTP q行库设|。该节可以在计算机、站炏V应用程序和子目录别声明?BR> CZQ控制用户上传文件最大ؓ4MQ最长时间ؓ60U,最多请求数?00
6?QpagesQ?BR> 作用Q标识特定于늚配置讄Q如是否启用会话状态、视囄态,是否用L输入{)。<pagesQ可以在计算机、站炏V应用程序和子目录别声明?BR> CZQ不用户在览器输入的内容中是否存在潜在的危险数据Q注Q该w认是,如果你用了不检,一要对用户的输入进行编码或验证)Q在从客L回发|检查加密的视图状态,以验证视囄态是否已在客L被篡攏V?注:该项默认是不验证Q?BR>
7、<sessionStateQ?BR> 作用Qؓ当前应用E序配置会话状态设|(如设|是否启用会话状态,会话状态保存位|)?BR> CZQ?BR>
注: mode="InProc"表示Q在本地储存会话状态(你也可以选择储存在远E服务器或SAL服务器中或不启用会话状态) cookieless="true"表示Q如果用h览器不支持Cookie时启用会话状?默认为FalseQ?BR> timeout="20"表示Q会话可以处于空闲状态的分钟?BR> 8、<traceQ?BR> 作用Q配|?ASP.NET 跟踪服务Q主要用来程序测试判断哪里出错?BR> CZQ以下ؓWeb.config中的默认配置Q?BR>
注: enabled="false"表示不启用跟t;requestLimit="10"表示指定在服务器上存储的跟踪h的数? pageOutput="false"表示只能通过跟踪实用工具讉K跟踪输出Q?BR> traceMode="SortByTime"表示以处理跟t的序来显Ct信?BR> localOnly="true" 表示跟踪查看?(trace.axd) 只用于宿?Web 服务?BR> 三、自定义Web.config文g配置?BR> 自定义Web.config文g配置节过E分Z步?BR> 一是在在配|文仉?QconfigSectionsQ??Q?configSectionsQ标C间声明配|节的名U和处理该节中配|数据的 .NET Framework cȝ名称?BR> 二是?QconfigSectionsQ?区域之后为声明的节做实际的配|设|?BR> CZQ创Z个节存储数据库连接字W串
四、访问Web.config文g 你可以通过使用ConfigurationSettings.AppSettings 静态字W串集合来访?Web.config 文gCZQ获取上面例子中建立的连接字W串?BR>
|
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data.OleDb;
namespace WebExportReport
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected DataSet dataSet = new DataSet();
// CR Variables
ReportDocument crReportDocument;
ExportOptions crExportOptions;
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer2;
DiskFileDestinationOptions crDiskFileDestinationOptions;
private void Page_Load(object sender, System.EventArgs e)
{
}
private void initDataSet()
{
string querySql ="select * from tblLotTrack where lot< 535120 and stn < 5000 ";
OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= c:\LTS2005.mdb");
cn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(querySql,cn);
adapter.SelectCommand = new OleDbCommand(querySql, cn);
adapter.Fill(dataSet);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
initDataSet();
//Create an instance of the strongly-typed report object
crReportDocument = new CrystalReport1();
crReportDocument.SetDataSource(dataSet);
CrystalReportViewer2.ReportSource = crReportDocument;
// *******************************************
// Initialize Dropdownlist for Format types
// *******************************************
DropDownList1.Items.Add("");
DropDownList1.Items.Add("Rich Text (RTF)");
DropDownList1.Items.Add("Portable Document (PDF)");
DropDownList1.Items.Add("MS Word (DOC)");
DropDownList1.Items.Add("MS Excel (XLS)");
DropDownList1.Items.Add("Crystal Report (RPT)");
DropDownList1.Items.Add("HTML 3.2 (HTML)");
DropDownList1.Items.Add("HTML 4.0 (HTML)");
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ExportReport()
{
// This subroutine uses a case statement to determine the selected export format from the dropdownlist
// menu and then sets the appropriate export options for the selected export format. The report is
// exported to a subdirectory called "Exported".
// ********************************
//Check to see if the application directory has a subdirectory called "Exported".
//If not, create the directory since exported files will be placed here.
//This uses the Directory class of the System.IO namespace.
string ExportPath;
ExportPath = Request.PhysicalApplicationPath + "Exported\\";
if (Directory.Exists(ExportPath) == false) Directory.CreateDirectory(Request.PhysicalApplicationPath + "Exported\\");
// ********************************
// First we must create a new instance of the diskfiledestinationoptions class and
// set variable called crExportOptions to the exportoptions class of the reportdocument.
crDiskFileDestinationOptions = new DiskFileDestinationOptions();
crExportOptions = crReportDocument.ExportOptions;
//Find the export type specified in the dropdownlist and export the report. The possible export format
//types are Rich Text(RTF), Portable Document (PDF), MS Word (DOC), MS Excel (XLS), Crystal Report (RPT),
//HTML 3.2 (HTML) and HTML 4.0 (HTML)
//
//Though not used in this sample application, there are options that can be specified for various format types.
//When exporting to Rich Text, Word, or PDF, you can use the PdfRtfWordFormatOptions class to specify the
//first page, last page or page range to be exported.
//When exporting to Excel, you can use the ExcelFormatOptions class to specify export properties such as
//the column width etc.
if (DropDownList1.SelectedItem.Text == "Rich Text (RTF)")
{
//--------------------------------------------------------------------
//Export to RTF.
//append a filename to the export path and set this file as the filename property for
//the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "RichTextFormat.rtf";
//set the required report ExportOptions properties
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.RichText;
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//--------------------------------------------------------------------
}
else if (DropDownList1.SelectedItem.Text == "Portable Document (PDF)")
{
//--------------------------------------------------------------------
//Export to PDF
//append a filename to the export path and set this file as the filename property for
//the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "PortableDoc.pdf";
//set the required report ExportOptions properties
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
//--------------------------------------------------------------------
}
else if (DropDownList1.SelectedItem.Text == "MS Word (DOC)")
{
//--------------------------------------------------------------------
//Export to Word
//append a filename to the export path and set this file as the filename property for
//the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Word.doc";
//set the required report ExportOptions properties
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.WordForWindows;
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//--------------------------------------------------------------------
}
else if (DropDownList1.SelectedItem.Text == "MS Excel (XLS)")
{
//--------------------------------------------------------------------
//Export to Excel
//append a filename to the export path and set this file as the filename property for
//the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Excel.xls";
//set the required report ExportOptions properties
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.Excel;
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//--------------------------------------------------------------------
}
else if (DropDownList1.SelectedItem.Text == "Crystal Report (RPT)")
{
//--------------------------------------------------------------------
//Export to Crystal reports:
//append a filename to the export path and set this file as the filename property for
//the DestinationOptions class
crDiskFileDestinationOptions.DiskFileName = ExportPath + "Report.rpt";
//set the required report ExportOptions properties
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.CrystalReport;
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
//--------------------------------------------------------------------
}
else if (DropDownList1.SelectedItem.Text == "HTML 3.2 (HTML)")
{
//--------------------------------------------------------------------
//Export to HTML32:
HTMLFormatOptions HTML32Formatopts = new HTMLFormatOptions();
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.HTML32;
HTML32Formatopts.HTMLBaseFolderName = ExportPath + "Html32Folder"; //Foldername to place HTML files
HTML32Formatopts.HTMLFileName = "HTML32.html";
HTML32Formatopts.HTMLEnableSeparatedPages = false;
HTML32Formatopts.HTMLHasPageNavigator = false;
crExportOptions.FormatOptions = HTML32Formatopts;
//--------------------------------------------------------------------
}
else if (DropDownList1.SelectedItem.Text == "HTML 4.0 (HTML)")
{
//--------------------------------------------------------------------
//Export to Html 4.0:
HTMLFormatOptions HTML40Formatopts = new HTMLFormatOptions();
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.HTML40;
HTML40Formatopts.HTMLBaseFolderName = ExportPath + "Html40Folder"; // Foldername to place HTML files
HTML40Formatopts.HTMLFileName = "HTML40.html";
HTML40Formatopts.HTMLEnableSeparatedPages = true;
HTML40Formatopts.HTMLHasPageNavigator = true;
HTML40Formatopts.FirstPageNumber = 1;
HTML40Formatopts.LastPageNumber = 3;
crExportOptions.FormatOptions = HTML40Formatopts;
} //export format
//Once the export options have been set for the report, the report can be exported. The Export command
//does not take any arguments
try
{
// Export the report
crReportDocument.Export();
}
catch (Exception err)
{
Response.Write("<BR>");
Response.Write(err.Message.ToString());
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
//Clicking on the "Export Report" button will run the ExportReport subroutine and export the report based on the
//selected format from the dropdownlist.
ExportReport();
}
}
}
http://www.weste.net/html/200408/20040825QBI101746.html
1?STRONG>升
下蝲水晶报表10。安装时选择.NETlg。如果VS2003已经安装好会自动其内置水晶报表升?0
License : AV860-01CS00G-U7000NC SN : 1231467890
2、?BR>拖一个CrystalReportViewer到Form?BR>d新项目,选择水晶报表。安装向D接数据库选择表即可徏成rpt文g?BR>d如下代码Q?BR> private void Page_Load(object sender, System.EventArgs e)
{
initDataSet();
//Create an instance of the strongly-typed report object
LotTrackCross crReportDocument = new LotTrackCross();
//Pass the populated dataset to the report
crReportDocument.SetDataSource(dataSet);
//Set the viewer to the report object to be previewed.
CrystalReportViewer1.ReportSource = crReportDocument;
}
private void initDataSet()
{
string querySql ="select * from tblLotTrack where lot< 535120 and stn < 5000 ";
OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= c:\LTS2005.mdb");
cn.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter(querySql,cn);
adapter.SelectCommand = new OleDbCommand(querySql, cn);
adapter.Fill(dataSet);
}
注意Q填充用的DataSet要和建立rpt文g的表名、列名对?/P>
我用建立sqlDataAdaper的方法获得连接字W串Q第一ơ选择q接的时候选择信Qq接
得到字符串如下。出现如上错?br /> workstation id=CLEVER06;packet size=4096;user id=sa;password=sa;integrated security=SSPI;
data source=Clever06;persist security info=False;initial catalog=IPDataBase
W二ơ不使用信Qq接
workstation id=CLEVER06;packet size=4096;user id=sa;password=sa;data source=clever06;persist security
info=False;initial catalog=IPDataBase
错误消失
Visual Studio .NET cannot create the application <application>. The likeliest problem is
that required components are not installed on the local Web server
原因一Qasp.net framework没有被注册,使用aspnet_regiis /i 注册卛_?br /> 原因二,没有为应用程序徏立虚拟目录?/font>
文g夹属性没有安全设|选项
公司有域环境Q电脑没有加入域Q加入后卛_
Web Service是一U具有下列功能的软glgQ?
?可以通过SOAP 接口(Simple Object Access Protocol单对象访问协? 接口来进行访??
?它是使用WSDL(Web Service Description LanguageQWeb Service描述语言 ) 文形式描述的接口?/P>
一、徏立一个WebService
打开.NET。新建工E。选择ASP.NET WEBSERVICE。确定。可以看到Service1.asmx.cs文g中有一个被注释掉的HelloWorld() example?/P>
L注释。即可得C个WebService的HelloWorldҎ?/P>
如果你愿意还可以d别的Ҏ?/P>
q行卛_看到你的可供调用的WebServiceҎ的列表?/P>
二、调用WebService
新徏一个Windows Application?/P>
?NET中的调用相对单。微软已l做好了中间的代理类Q只有我们稍微做一下配|即可?/P>
在SolutionExplor中右击Reference。添加WebReference。在URL栏中填入刚才WebServiceq行的地址。例如:http://localhost/WebService1/Service1.asmx。点击GoQ即可看C的WebServiceҎ列表。点L加引用?/P>
在Form上添加一个按钮和一个文本框。在按钮的点M件添加如下代码:
WindowsApplication1.WebReference.Service1 test = new WindowsApplication1.WebReference.Service1(); this.textBox1.Text = test.HelloWorld(); |
在运行后点击按钮Q可以看到文本框中的文本变成了Hello World。WebService调用成功?BR>?/FONT>Q?BR>在调用WebService时出现如下错误System.Net.WebException: The request failed with HTTP status 401:
Access Denied。在|上搜烦一下发现出现这U错误的很多。原因不详。但是基本是权限问题造成的?BR>我做了如下尝?BR>●文件夹权限ҎEveryOne都可以访问?BR>●添加引用的时候把localhostҎ127.0.0.1?BR>●把ASPNET用户d到管理员l?BR>但是都没有奏效。然后我重新安装了IIS。发现可以了。仍然不知道是什么原因造成的。暂做记录。以备后查?BR>
事g的参?SPAN lang=EN-US>
private void Button3_Click(object sender, System.EventArgs e)
一般来_事g的相应方法会有两个参敎ͼ
参数Q?B style="mso-bidi-font-weight: normal">object sender
其中一个代表引发事件的对象?SPAN lang=EN-US>sender。由于引发事件的对象是不可知的,因此我们把其声明?SPAN lang=EN-US>objectcd。所有对象都适用?SPAN lang=EN-US>
Button s = (Button)sender;
string a = s.Text;
参数Q?B>EventArgs
W二个参C表引发事件的具体信息?/SPAN>下面?SPAN lang=EN-US>MSDN对这个类的描q?/SPAN>
This class contains no event data; it is used by events that do not pass state information to an event handler when an event is raised. If the event handler requires state information, the application must derive a class from this class to hold the data
各种事g中的cd可能不同。但是都是从EventArgsl承而来。例?B>
DataGridItemEventArgs
The ItemCreated event is raised when an item in the DataGrid control is created.
The ItemDataBound event is raised when an item in the DataGrid control is data bound to a source.
事g的定?SPAN lang=EN-US>
如何定义事gQ?SPAN lang=EN-US>
[attributes] [modifiers] event type declarator;
type
The delegate to which you want to associate this event.
例如Q?SPAN lang=EN-US>public event MyDelegate MyEvent;
namespace CSharpConsole
{
public class 场景
{
[STAThread]
public static void Main(string[] args)
{
Console.WriteLine("场景开始了....");
// 生成王
王 w = new 王();
// 生成̎
张 z = new 张();
// 指定监视
z.PlayGame += new PlayGameHandler(w.扣钱);
// 开始玩游戏
z.玩游?);
Console.WriteLine("场景l束...");
Console.ReadLine();
}
}
// 负责扣钱的h
public class 王
{
public 王()
{
Console.WriteLine("生成王...");
}
public void 扣钱(object sender,EventArgs e)
{
Console.WriteLine("王Q好子Q上班时间胆敢玩游戏...");
Console.WriteLine("王Q看看你子有多钱...");
张 f = (张)sender;
Console.WriteLine("张的钱Q?" + f.?ToString());
Console.WriteLine("开始扣?.....");
System.Threading.Thread.Sleep(500);
f.?= f.?- 500;
Console.WriteLine("扣完?...现在张q剩下:" + f.?ToString());
}
}
// 如果玩游戏,则引发事?BR> public class 张
{
// 先定义一个事Ӟq个事g表示“小张”在玩游戏?BR> public event PlayGameHandler PlayGame;
// 保存张q变量
private int m_Money;
public 张()
{
Console.WriteLine("生成张....");
m_Money = 1000; // 构造函敎ͼ初始化小张的钱?BR> }
public int ?// 此属性可以操作小张的钱?BR> {
get
{
return m_Money;
}
set
{
m_Money = value;
}
}
public void 玩游?)
{
Console.WriteLine("张开始玩游戏?....");
Console.WriteLine("张:CS好玩Q哈哈哈Q?我玩.....");
System.Threading.Thread.Sleep(500);
System.EventArgs e = new EventArgs();
OnPlayGame(e);
}
protected virtual void OnPlayGame(EventArgs e)
{
if(PlayGame != null)
{
PlayGame(this,e);
}
}
}
// 定义委托处理E序
public delegate void PlayGameHandler(object sender,System.EventArgs e);
}
public static void MessageBox( System.Web.UI.Page page, string msg ) { StringBuilder StrScript = new StringBuilder(); StrScript.Append( "<script language=javascript>" ); StrScript.Append( "alert('"+ msg +"');" ); StrScript.Append( "</script>" ); if ( ! page.IsStartupScriptRegistered( "MessageBox" ) ) { page.RegisterStartupScript( "MessageBox", StrScript.ToString() ); } } |
LinkButton delLink = new LinkButton(); if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { delLink = (LinkButton)(e.Item.Cells[0].Controls[0]); delLink.Attributes.Add("onClick","Javascript:return confirm('Are you sure to delete the record ?');"); } |
DataGridPaging.aspx
DataGridPaging.aspx.cs
VB.NET版本
DataGridPaging.aspx
DataGridPaging.aspx.vb
Ҏ2Q完全后代码写法Q?/FONT>例子
DataGridPaging2.aspx
DataGridPaging2.aspx.cs
;提示 promptCulture = 请选择希望用来查看此示例的区域?==> promptName = 误入您的姓?==> ;距离 ;温度量度 |
每个不同版本?NET框架都包含ASP.NET IIS注册工具(Aspnet_regiis.exe)。该工具允许理员指定WEB应用E序q行在不同的.NET框架中。不同版?NET框架的aspnet_regiis.exe存在于各自的目录下,例如理员希望指定某个网站?.1版本?NET框架Q则必须使用.NET框架1.1所在目录下的aspnet_regiis.exe文g?BR>
.NET框架1.0版本中的aspnet_regiis.exe位于Q?BR>
注:你也可以使用名ؓMetabase Editor的工h获得应用E序的元路径。可以在微Y|站?/FONT>http://support.microsoft.com/default.aspx?scid=kb;en-us;232068. 下蝲?BR>q行"Aspnet_regiis.exe –s W3SVC/1/ROOT/Portal"来指定portal及其子目录的应用E序使用该当前脚本配|?/FONT>
q行"Aspnet_regiis.exe –sn W3SVC/1/ROOT/Portal"来指定portal使用该脚本配|,不媄响其子目录中的应用程?BR>
ASP.NET WEB FORMS l开发者提供了极好的事仉动开发模式。然而这U简单的应用E序开发模式却l我们带来了一些小问题QD个例子,在传l的ASP应用E序中,你能够通过POSTҎ很容易的把一个值或多个g一个页面传送到另一个页面,用同LҎ在ASP.NET中实现有炚w烦。在q里Q我们可以通过其他方式来解册U情形。ASP.NET为我们提供了三种方式Q一U是可以通过用QueryString来传送相应的|再一U是通过session变量来传送相应的|q有是通过Server.TransferҎ来实现。下面分别一一介绍Q?/FONT>
一、用Querystring
Querystring是一U非常简单的传值方式,其缺点就是会把要传送的值显C在览器的地址栏中Qƈ且在此方法中不能够传递对象。如果你想传递一个安全性不是那么太重要或者是一个简单的数值时Q用此方法最好不q了。下面通过一个小例子来完成传值工作,步骤如下Q?BR>1、创Z个web form
2、在新徏的web form中放|一个button1Q在攄两个TextBox1,TextBox2
3、ؓbutton按钮创徏click事g
代码如下Q?BR>private void Button1_Click
(object sender, System.EventArgs e)
{
string url;
url="webform2.aspx?name=" +
TextBox1.Text + "&email=" +
TextBox2.Text;
Response.Redirect(url);
}
4、新Z个目标页面命名ؓwebform2
5、在webform2中放|两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Request.QueryString["name"];
Label2.Text=Request.QueryString["email"];
}
q行,卛_看到传递后的结果了?/FONT>
二、用Session变量
使用Session变量传值是一U最常见的方式了Q此中方式不仅可以把g递到下一个页面,q可以交叉传递到多个面Q直xSession变量的值removed后,变量才会消失。D个例子看看:
1、创Z个web form
2、在新徏的web form中放|一个button1Q在攄两个TextBox1,TextBox2
3、ؓbutton按钮创徏click事g
代码如下Q?BR>private void Button1_Click
(object sender, System.EventArgs e)
{
Session["name"]=TextBox1.Text;
Session["email"]=TextBox2.Text;
Response.Redirect("webform2.aspx");
}
4、新Z个目标页面命名ؓwebform2
5、在webform2中放|两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
Label1.Text=Session["name"].ToString();
Label2.Text=Session["email"].ToString();
Session.Remove("name");
Session.Remove("email");
}
q行,卛_看到传递后的结果了?/FONT>
三、用Server.Transfer
虽然q种Ҏ有点复杂Q但也不׃ؓ一U在面传值的方式?BR>举个例子看看Q?BR>1、创Z个web form
2、在新徏的web form中放|一个button1Q在攄两个TextBox1,TextBox2
3、ؓbutton按钮创徏click事g
代码如下Q?BR>private void Button1_Click
(object sender, System.EventArgs e)
{
Server.Transfer("webform2.aspx");
}
4、创E来q回TextBox1,TextBox2控g的g码如下:
public string Name
{
get
{
return TextBox1.Text;
}
}
public string EMail
{
get
{
return TextBox2.Text;
}
}
5、新Z个目标页面命名ؓwebform2
6、在webform2中放|两个Label1,Label2
在webform2的Page_Load中添加如下代码:
private void Page_Load
(object sender, System.EventArgs e)
{
//创徏原始H体的实?BR> WebForm1 wf1;
//获得实例化的句柄
wf1=(WebForm1)Context.Handler;
Label1.Text=wf1.Name;
Label2.Text=wf1.EMail;
}
q行,卛_看到传递后的结果了?/FONT>
OleDbCommand myCommand = myConnection.CreateCommand();
OleDbTransaction myTrans;
myTrans = myConnection.BeginTransaction(IsolationLevel.ReadCommitted);
myCommand.Connection = myConnection;
myCommand.Transaction = myTrans;
try
{
myCommand.CommandText = "Insert into test (name, address) VALUES ('Liu', 'Japan')";
myCommand.ExecuteNonQuery();
myCommand.CommandText = "Insert into test (name, address) VALUES ('Mark', Germany')";
myCommand.ExecuteNonQuery();
myTrans.Commit();
Console.WriteLine("Both records are written to database.");
}
catch(Exception ex)
{
try
{
myTrans.Rollback();
}
catch (OleDbException oex)
{
if (myTrans.Connection != null)
{
this.Label1.Text = this.Label1.Text + oex.GetType() ;
}
}
this.Label1.Text = this.Label1.Text + ex.GetType();
this.Label1.Text = this.Label1.Text+"Neither record was written to database";
}
finally
{
myConnection.Close();
}
点击后即可在test表中加入记录
W一?/SPAN>Q在以上pȝ及Y件安装就l的情况下,配置IIS服务。(注意Q如果没有安?/SPAN>FrontPage 扩展服务Q在安装 .Net时会提示。安装提C,在添加删除组件中dFrontPage扩展服务 卛_Q?/SPAN>
控制面板Q?/SPAN>>d删除E序Q?/SPAN>>d删除windowslg
选择iis服务Q安默认安装?/SPAN>
理工具Q?/SPAN>>Internet 信息服务,q里可以更改ȝ录的路径Q也可以保持默认倹{?/SPAN>
W二?/SPAN>Q在ACCESS中徏?/SPAN>
建立I白数据库,建立?/SPAN>AddressQ?/SPAN>id,name,addressQ添加两条数据。关?/SPAN>Access?/SPAN>
W三?/SPAN>Q打开.NetQ新Z个工E?/SPAN>
新徏工程Q?/SPAN>Project Types 选择cQ,Template选择Asp.NET Web Application(q里要注意,W一ơ用时会蟩出如下的对话框,要安帮助信息注册Asp.net)
在旁边的Toolbox拖一个按钮?/SPAN>
?/SPAN>data区拖一?/SPAN>oledbdataadapter。按照向导如下?/SPAN>
叛_oledbdataadapter1?/SPAN>Genertate dataset
?/SPAN>webform中选择datagrid。设|?/SPAN>datasource?/SPAN>dataset1
在按钮的点击事g中增加如下代码:
this.oleDbDataAdapter1.Fill(this.dataSet11);
this.DataGrid1.DataBind();
q行。点L钮就可以看到数据表中的数据了?/FONT>