动态加载页面--小练

------动态加载页面不使用iframe ,Javascript ,include [<!--#include file="文件名地址"-->]-------------

<ul style="list-style-type:none;margin:0;padding:0;">

<li style=" text-decoration:underline"><a href="MIni.aspx?id=1">sfsfsfd</a></li>

<li class="list1"><a href="MIni.aspx?id=2">sfsfsfd</a></li>

<li class="list2"><a href="MIni.aspx?id=3">sfsfsfd</a></li>

<li><a href="MIni.aspx?id=4">sfsfsfd</a></li>

<li><a href="MIni.aspx?id=5">sfsfsfd</a></li>

</ul>

---------------------------------------------------------------------------------------------

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

{

protected vo id Page_Load(object sender, EventArgs e)

{

string strId = RequestUtility.GetNonNullQueryString("id");

string strPath = Server.MapPath(string.Format("Uploads/list{0}.htm", strId));

// this.test.InnerHtml = GetPageSource(strPath);

this.test.InnerHtml = GetPageHhml(strPath);

}

/// <summary>

/// 本地

/// </summary>

/// <param name="path"></param>

/// <returns></returns>

public static string GetPageHhml(string path)

{

string result = null;

if (File.Exists(path))

{

//FileStream fs = new FileStream(path, FileMode.Open);

//StreamReader sr = new StreamReader(path, System.Text.Encoding.Default);

//result = sr.ReadToEnd();

//sr.Close();

//fs.Close();

using (StreamReader sr = new StreamReader(path, System.Text.Encoding.Default))

{

result = sr.ReadToEnd();

}

}

return result;

}

public static string GetPageSource(string strPath)

{

string result = null;

if (File.Exists(strPath))

{

Uri uri = new Uri(strPath);//Uri uri = new Uri("www.baidu.com");

WebClient wb = new WebClient();

wb.Credentials = CredentialCache.DefaultCredentials;

byte[] pagedata = wb.DownloadData(@uri);

result = System.Text.Encoding.UTF8.GetString(pagedata);

}

return result;

}

}

--------------------------------------修改后---MIni.aspx.cs---------------------------------------------------------------------

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.IO;

using Lodge.ToolKit.Common;

using System.Text;

using System.Text.RegularExpressions;

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

{

protected string strJobContent = "";

static Regex reg = new Regex(@"<p class=['""]career_title['""]>(?<title>.*?)</p>", RegexOptions.IgnoreCase);

protected void Page_Load(object sender, EventArgs e)

{

string strId = RequestUtility.GetNonNullQueryString("id");

if (strId != null)

{

string strPath = Server.MapPath(string.Format("Uploads/list{0}.htm", strId));

//MainContent(strId);

GetPageHhml(strPath);

}

}

/// <summary>

/// 本地

/// </summary>

/// <param name="path"></param>

/// <returns></returns>

private void GetPageHhml(string path)

{

if (File.Exists(path))

{

using (StreamReader sr = new StreamReader(path, System.Text.Encoding.Default))

{

strJobContent = sr.ReadToEnd();

Match match = reg.Match(strJobContent);

if (match != "")

{

string strTitle = match.Groups["title"].Value;

Page.Title = strTitle + " " + Page.Title;

}

}

}

}

}

-------------Uploads/list1.htm----------

<div class="list1" style="width:500px;height:500px;background-color:Green;margin-top:5px;">

<p class="career_title">简历搜索</p>

无标题页无标题页无标题页fddffdfdfd

</div>

-------------MIni.aspx----------

<ul style="list-style-type:none;margin:0;padding:0;">

<li style=" text-decoration:underline"><a href="MIni.aspx?id=1">简历搜索</a></li>

<li class="list1"><a href="MIni.aspx?id=2">sfsfsfd</a></li>

<li class="list2"><a href="MIni.aspx?id=3">sfsfsfd</a></li>

<li><a href="MIni.aspx?id=4">sfsfsfd</a></li>

<li><a href="MIni.aspx?id=5">sfsfsfd</a></li>

</ul>

<div>

<%=strJobContent %>

</div>

---------------------------------------------------------项目-----------------------------------------------------------------

<div id="main_left">

<ul>

<li><a href="/Jobs/jobDetail.aspx?name=job1">网页设计师</a></li>

<li><a href="/Jobs/jobDetail.aspx?name=job2">C++程序员(客户端程序员)</a></li>

<li><a href="/Jobs/jobDetail.aspx?name=job3">游戏策划</a></li>

<li><a href="/Jobs/jobDetail.aspx?name=job4">3D美术设计师</a></li>

<li><a href="/Jobs/jobDetail.aspx?name=job5">C++程序员(服务端程序员)</a></li>

<li><a href="/Jobs/jobDetail.aspx?name=job6">游戏客服</a></li>

</ul>

</div>

-----------------------------------------------

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

{

protected string strJobContent = "";

static Regex regJobTitle = new Regex(@"<p class=['""]career_title['""]>(?<title>.*?)</p>", RegexOptions.IgnoreCase);

const string JOB_FILE_PATH = @"~/jobs/job/{0}.html";

protected void Page_Load(object sender, EventArgs e)

{

string strName = RequestUtility.GetNonNullQueryString("name");

if (strName == "" || File.Exists(Server.MapPath(string.Format(JOB_FILE_PATH, strName))) == false)

strName = "job1";

using (StreamReader sr = new StreamReader(Server.MapPath(string.Format(JOB_FILE_PATH, strName)), Encoding.Default))

{

strJobContent = sr.ReadToEnd();

Match match = regJobTitle.Match(strJobContent);

if (match != null)

{

string strTitle = match.Groups["title"].Value;

Page.Title = strTitle + " " + Page.Title;

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值