ASP.NET动态加载用户控件的页面生成过程
MainPage文件:WebForm1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="TestMasterPage.WebForm1" enableViewState="False"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder></form>
</body>
</HTML>
WebForm1.aspx.cs
using System;
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;
namespace TestMasterPage
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1; private void Page_Load(object sender, System.EventArgs e)
{
//在此处放置用户代码以初始化页面
string controlName = "search.ascx";
UserControl control = (UserControl)LoadControl("~/skins/default/controls/"+ controlName);
control.ID = "ID_" + controlName; PlaceHolder1.Controls.Add(control); Response.Write("only trace..");
}
Web窗体设计器生成的代码Web窗体设计器生成的代码
override protected void OnInit(EventArgs e)
相关文档:
@Page指令位于每个ASP.NET页面的顶部,告诉ASP.NET这个具体页面使用什么属性,以及该页面继承的用户控件。ASP.NET页面
@Page指令属性有:AspCompat、Async、AsyncTimeout、AutoEventWireup、Buffer、
ClassName、ClientIDMode、CodeBehind、
CodeFile、CodeFileBaseClass、CodePage、CompilationMode 、ContentType、
......
asp.net 获取客户端计算机名
1. 在ASP.NET中专用属性:
获取服务器电脑名:Page.Server.ManchineName
获取用户信息:Page.User
获取客户端电脑名:Page.Request.UserHostName
获取客户端电脑IP:Page.Request.UserHostAddress
2. 在网络编程中的通用方法:
获取当前电脑名:static System.Net.Dns.GetHostNam ......
//ASP.NET获取中文首字母
public class Converter
{
static public string GetChineseSpell(string strText)
{
......
动态页面生成静态页面说起来其实不难,主要是思想的问题,像那些新闻不太常改动的,我们可以将他生成静态的,来提高网站的访问速度,以下就是我的方法,很简单
我们先将我们的动态网站放到网上,并且可以正常访问,然后就是用到了抓取页面的技术了
/// <summary>
/// 获得网页内容
& ......
获取网站根目录的方法有几种如:
Server.MapPath(Request.ServerVariables["PATH_INFO"])
Server.MapPath("/")
Server.MapPath("")
Server.MapPath(".")
Server.MapPath("../")
Server.MapPath("..")
&nb ......