我为了提高速度!我想在内容提交的时候将主页的ASPX生成HTM
我就写了一个按钮事件
void btnNext1_ServerClick(object sender, System.EventArgs e)
{
System.Web.UI.Page page=new Page();
StringWriter writer = new StringWriter();
string Filepath = "../../_MAINPAGE/sjiframe/sjiframe.aspx";
string outpath = "../../_MAINPAGE/sjiframe/jtsj.htm";
page.Server.Execute(Filepath, writer);
FileStream fs;
if(File.Exists(page.Server.MapPath("")+"\\"+outpath))
{
File.Delete(page.Server.MapPath("")+"\\"+outpath);
}
fs=File.Create(page.Server.MapPath("")+"\\"+outpath);
byte[] bt=System.Text.Encoding.Default.GetBytes(writer.ToString());
fs.Write(bt,0,bt.Length);
fs.Close(); }
按钮如下:
<INPUT class="button" id="btnNext1" value="生成" type="button" name="btnNext1" runat="server" onserverclick="btnNext1_ServerClick">现在的问题是进入这个页面后我一点按钮就报错!说我网站APSX主页里调用其他模块错误!!
但我如果把这段代码加到PAGE_LOAD里的话就没问题!可以正常生成HTM!但我接着点页面上的任何按钮就都会报错!说我网站APSX主页里调用其他模块错误!!我有些迷糊了!到底是哪里错了呢?!希望大家帮忙找找原因!!谢谢谢谢了
我就写了一个按钮事件
void btnNext1_ServerClick(object sender, System.EventArgs e)
{
System.Web.UI.Page page=new Page();
StringWriter writer = new StringWriter();
string Filepath = "../../_MAINPAGE/sjiframe/sjiframe.aspx";
string outpath = "../../_MAINPAGE/sjiframe/jtsj.htm";
page.Server.Execute(Filepath, writer);
FileStream fs;
if(File.Exists(page.Server.MapPath("")+"\\"+outpath))
{
File.Delete(page.Server.MapPath("")+"\\"+outpath);
}
fs=File.Create(page.Server.MapPath("")+"\\"+outpath);
byte[] bt=System.Text.Encoding.Default.GetBytes(writer.ToString());
fs.Write(bt,0,bt.Length);
fs.Close(); }
按钮如下:
<INPUT class="button" id="btnNext1" value="生成" type="button" name="btnNext1" runat="server" onserverclick="btnNext1_ServerClick">现在的问题是进入这个页面后我一点按钮就报错!说我网站APSX主页里调用其他模块错误!!
但我如果把这段代码加到PAGE_LOAD里的话就没问题!可以正常生成HTM!但我接着点页面上的任何按钮就都会报错!说我网站APSX主页里调用其他模块错误!!我有些迷糊了!到底是哪里错了呢?!希望大家帮忙找找原因!!谢谢谢谢了
<%@ Page language="c#"%>
<%@ Import Namespace="System.Xml"%>
<%@ Import Namespace="System.Xml.Xsl"%>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="comm"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<%
Ebuilder.Login Obj = new Ebuilder.Login () ;
Obj.IfLogin ("01",Request,Response);
%>
<HTML>
<HEAD>
<title>发布管理</title>
<script src="/admin/common/check.js"></script>
<LINK href="/admin/css/manager.css" type="text/css" rel="stylesheet">
<script language="c#" runat="server">
data ds = new data();
DataSet dsLikai = new DataSet() ;
string lm="";
string cfile ;
string rpath ;
private int PageSize
{
get
{
return 10 ;
}
}
private int PageCount
{
get
{
return Int32.Parse(pagecount.Value.ToString()) ;
}
set
{
pagecount.Value = value.ToString() ;
}
} private int CurrentPage
{
get
{
int page = Int32.Parse(currentpage.Value.ToString()) ;
if(page < 1 )
{
page = 1 ;
}
if(page > PageCount)
{
page = PageCount ;
} return page ;
}
set
{
int page = value ;
if(page < 1)
{
page = 1 ;
}
if(page > PageCount)
{
page = PageCount ;
}
currentpage.Value = page.ToString() ;
}
} void btnFirst_ServerClick(object sender, System.EventArgs e)
{
CurrentPage = 1 ;
} void btnPrevious_ServerClick(object sender, System.EventArgs e)
{
CurrentPage -= 1 ;
} void btnNext_ServerClick(object sender, System.EventArgs e)
{
CurrentPage += 1 ;
} void btnLast_ServerClick(object sender, System.EventArgs e)
{
CurrentPage = PageCount ;
} void btnGo_ServerClick(object sender, System.EventArgs e)
{
try
{
CurrentPage = Int32.Parse(txtGo.Value.ToString()) ;
}
catch
{}
} void Page_Load(object sender, System.EventArgs e)
{ if(!this.IsPostBack)
{ commTools cc=new commTools();
if(Request.Params["entity"].IndexOf("S")!=-1)
{
path.Value=cc.FindpathS(this.MapPath("/"),Request.Params["entity"]);
}
else
{
path.Value=cc.FindpathL(this.MapPath("/Lists"),Request.Params["entity"]);
}
} cfile=path.Value+"\\_config\\config.xml";
if(File.Exists(cfile))
{
rpath=Request.Params["entity"].IndexOf("S")==-1?path.Value.Substring(path.Value.IndexOf("\\Lists")):path.Value.Substring(MapPath("/").Length); ds.ReadXml(path.Value+"\\_config\\config.xml");
data ds1=new data();
if(File.Exists(path.Value.Substring(0,path.Value.LastIndexOf('\\'))+"\\_config\\config.xml"))
{
ds1.ReadXml(path.Value.Substring(0,path.Value.LastIndexOf('\\'))+"\\_config\\config.xml");
DataRow []drs=ds1.subs.Select("id='"+ds.entity.Rows[0]["id"]+"'");
if(drs.Length>0)
{
lm=drs[0]["name"].ToString();
}
}
}
}
void btnNext1_ServerClick(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
System.Web.UI.Page page=new Page();
StringWriter writer = new StringWriter();
string Filepath = "../../_MAINPAGE/sjiframe/sjiframe.aspx";
string outpath = "../../_MAINPAGE/sjiframe/jtsj.htm";
page.Server.Execute(Filepath, writer);
FileStream fs;
if(File.Exists(page.Server.MapPath("")+"\\"+outpath))
{
File.Delete(page.Server.MapPath("")+"\\"+outpath);
}
fs=File.Create(page.Server.MapPath("")+"\\"+outpath);
byte[] bt=System.Text.Encoding.Default.GetBytes(writer.ToString());
fs.Write(bt,0,bt.Length);
fs.Close();
}
} void delfile_ServerClick(object sender, System.EventArgs e)
{
int fp=(int )ds.entity.Rows[0]["firstpic"];
string[] rows=ct.Value.Split('#'); for(int i=0;i<rows.Length;++i)
{
DataRow []dr=ds.info.Select("id="+rows[i]);
if(dr.Length>0)
{
try
{
if(File.Exists(path.Value+"\\_uploads\\"+dr[0]["filename"]))
File.Delete(path.Value+"\\_uploads\\"+dr[0]["filename"]);
if(File.Exists(path.Value+"\\_uploads\\"+dr[0]["pic"]))
File.Delete(path.Value+"\\_uploads\\"+dr[0]["pic"]);
}
catch
{
Response.Write("<script"+" language='javascript'>alert('所选文件中有无法删除的文件!\\n\\n\\t请手工删除。');<"+"/script>");
} if((fp!=-1)&&(fp==(int )dr[0]["id"]))
ds.entity.Rows[0]["firstpic"]=-1;
dr[0].Delete();
}
} ds.WriteXml(path.Value+"\\_config\\config.xml");
Response.Write("<script"+">window.location.href='"+this.Request.UrlReferrer.ToString()+"';</script"+">");
}
void save_ServerClick(object sender, System.EventArgs e)
{
string[] tt=ct.Value.Split('$');
string[] rows=tt[0].Split('#');
ds.entity.Rows[0]["firstpic"]= Int32.Parse(tt[1]); for(int i=0;i<rows.Length;++i)
{
string[] row=rows[i].Split(';');
if(row[0]!="")
{
DataRow []dr=ds.info.Select("id="+row[0]);
if(dr.Length>0)
{
dr[0]["isPubs"]=System.Convert.ToBoolean(row[1]);
dr[0]["showid"]=row[2]==""?0:System.Convert.ToInt32(row[2]);
dr[0]["title"]=row[3];
}
}
}
ds.WriteXml(path.Value+"\\_config\\config.xml");
//Response.Redirect(this.Url);
}
</script>
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="javascript" id="clientEventHandlersJS">
<!--
function del_onclick()
{
colinfo.ct.value="";
var candel=0;
for(i=1;i<this.filelist.rows.length;i++)
{
var chkt=(document.all.delchk[i-1]==null)?colinfo.delchk:document.all.delchk[i-1];
if(chkt.checked==true)
{
colinfo.ct.value+=chkt.fileid+"#";
if(candel==0)
candel=1;
}
} if(candel)
{
if(confirm("您确定要删除所选择的文件吗?"))
{
colinfo.ct.value=colinfo.ct.value.substring(0,colinfo.ct.value.length-1);
colinfo.delfile.click();
}
}
else
{
alert("请选择删除项!");
}
return false;
}function pubclick(chk)
{
var ln=event.srcElement.ln;
var tb=(document.all.tb[ln-1]==null)?colinfo.tb:document.all.tb[ln-1];
tb.disabled=!chk.checked;
tb.value="";
}
function selchange(chk)
{
var ln=event.srcElement.ln;
var fp=(document.all.fp[ln-1]==null)?colinfo.fp:document.all.fp[ln-1];
if(fp.checked&&(document.all.fp[ln-1]!=null))
{
for(i=1;i<this.filelist.rows.length;i++)
{
document.all.fp[i-1].checked=false;
}
fp.checked=true;
colinfo.hidFirstpic.value = fp.value ;
}
}function saveclick()
{
var firstpic="-1";
colinfo.ct.value="";
for(i=1;i<this.filelist.rows.length;i++)
{
var chkt=(document.all.pubchk[i-1]==null)?colinfo.pubchk:document.all.pubchk[i-1];
var tb=(document.all.tb[i-1]==null)?colinfo.tb:document.all.tb[i-1];
var ft=(document.all.ftitle[i-1]==null)?colinfo.ftitle:document.all.ftitle[i-1];
var fp=(document.all.fp[i-1]==null)?colinfo.fp:document.all.fp[i-1]; if(chkt.checked)
{
if(tb.value!=""&&!isNum(tb.value))
{
alert("显示顺序只能是数字!");
return false;
}
} if(!checkTitle(ft.value))
{
alert("文件显示名称中不能有特殊字符!");
return false;
}
if(fp.checked)
firstpic= fp.value;
colinfo.ct.value+=tb.fileid+";"+chkt.checked+";"+tb.value+";"+ft.value+"#";
} colinfo.ct.value=colinfo.ct.value.substring(0,colinfo.ct.value.length-1);
colinfo.ct.value+="$"+ colinfo.hidFirstpic.value ;//firstpic;
colinfo.save1.click();
}//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<body MS_POSITIONING="GridLayout" class="body">
<form id="colinfo" runat="server">
<TABLE id="Table1" cellPadding="0" width="100%" align="center">
<TR>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20"> </td>
<td width="80">
<div align="center"><img src="/admin/images/list.gif" width="49" height="49"></div>
</td>
<TD class="font9"><a href="subsinfo.aspx?entity=<%=Request.Params["entity"]%>">栏目设置</a>——〉<%=lm%> 信息管理
</TD>
</tr>
</table>
</td>
</TR>
<tr>
<td width="584" height="10"></td>
</tr>
<tr bgcolor="#4E7ECF">
<td width="584" height="2"></td>
</tr>
<TR>
<TD>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20"> </td>
<td>
<INPUT id="delfile" style="DISPLAY: none" type="button" value="Button" name="Button1" runat="server" onServerClick="delfile_ServerClick">
<INPUT id="del" class="button" type="button" value="删除信息" name="del" onclick="del_onclick()">
<INPUT id="save2" runat="server" class="button" type="button" value="保存修改" name="Button1" onclick="saveclick()"></td>
</tr>
</table>
</TD>
</TR>
<td width="584" height="2"></td>
</tr>
<tr>
<td width="584" height="10"></td>
</tr> <tr>
<td>
<table width="100%" id="filelist" border="1" cellspacing="0" cellpadding="0" align="center" bordercolorlight="#000099" bordercolordark="#FFFFFF">
<tr>
<td class="htd">选择</td>
<td class="htd">发布</td>
<td class="htd">显示顺序</td>
<td class="htd">文件</td>
<td class="htd"> </td>
<td class="htd">图片</td>
<td class="htd">设为首页图片</td>
</tr>
<%
if(File.Exists(cfile))
{
dsLikai.ReadXml(path.Value+"\\_config\\config.xml") ;
hidFirstpic.Value = dsLikai.Tables["entity"].Rows[0]["firstpic"].ToString() ;
} if(dsLikai.Tables["info"] != null)
{
PageCount = dsLikai.Tables["info"].DefaultView.Count/PageSize ;
if(dsLikai.Tables["info"].DefaultView.Count%PageSize != 0)
{
PageCount += 1 ;
}
DataView dvInfo = dsLikai.Tables["info"].DefaultView ;
dvInfo.Sort = "showid,date desc" ; txtGo.Value = "" ; for(int i = (CurrentPage - 1)*PageSize ; i < CurrentPage*PageSize ; i++)
{
if(i >= dvInfo.Count)
{
break ;
} int ln = i + 1 - (CurrentPage-1)*PageSize;
%> <tr>
<td class="itd"><input type="checkbox" class="checkbox" id="delchk" fileid="<%=dvInfo[i]["id"]%>"></td>
<%
if(dvInfo[i]["ispubs"].ToString().ToUpper() == "TRUE")
{
%>
<td class="itd"><input type="checkbox" class="checkbox" id="pubchk" ln="<%=ln%>" onclick="pubclick(this)" checked></td>
<%
}
else
{
%>
<td class="itd"><input type="checkbox" class="checkbox" id="pubchk" ln="<%=ln%>" onclick="pubclick(this)"></td>
<%
}
%>
<td class="itd"><input type="text" class="text" id="tb" maxlength="7" size="10" fileid="<%=dvInfo[i]["id"]%>" value="<%=dvInfo[i]["showid"]%>"></td>
<td class="itd"><input type="text" class="text" id="ftitle" style="width:95%" value="<%=dvInfo[i]["title"]%>"></td>
<td class="ttd" nowrap="true"><a target="_blank" href="addNew.aspx?entity=<%=Request.Params["entity"]%>&subs=<%=Request.Params["entity"]%>&fid=<%=dvInfo[i]["id"]%>">查看</a></td>
<%
if(dvInfo[i]["pic"] == "")
{
%>
<td class="ttd" nowrap="true"><a href="upload.aspx?opt=1&entity=<%=Request.Params["entity"]%>&infoid=<%=dvInfo[i]["id"]%>">(上传图片)</a></td>
<%
}
else
{
%>
<td class="ttd" nowrap="true"><a href="<%=rpath%>/_uploads/<%=dvInfo[i]["pic"]%>" target="_blank"><%=dvInfo[i]["pic"]%></a></td>
<%
} if(hidFirstpic.Value.ToString() == dvInfo[i]["id"].ToString())
{
%>
<td class="itd" nowrap="true"><input type="checkbox" id="fp" name="fp" class="radio" value="<%=dvInfo[i]["id"]%>" ln="<%=ln%>" onclick="selchange(this)" checked></td>
<%
}
else
{
%>
<td class="itd" nowrap="true"><input type="checkbox" id="fp" name="fp" class="radio" value="<%=dvInfo[i]["id"]%>" ln="<%=ln%>" onclick="selchange(this)" ></td>
<%
}
%>
</tr>
<%
}
}
%>
</table>
</td>
</tr>
<TR>
<TD vAlign="top" align="middle" colSpan="2">
<INPUT id="save1" style="DISPLAY:none" type="button" name="Button1" runat="server" onserverclick="save_ServerClick">
</TD>
</TR>
<TR>
<TD vAlign="top" align="middle" colSpan="2">
<INPUT class="button" id="btnFirst" value="第一页" type="button" name="btnFirst" runat="server" onserverclick="btnFirst_ServerClick">
<INPUT class="button" id="btnPrevious" value="上一页" type="button" name="btnPrevious" runat="server" onserverclick="btnPrevious_ServerClick">
<INPUT class="button" id="btnNext" value="下一页" type="button" name="btnNext" runat="server" onserverclick="btnNext_ServerClick">
<INPUT class="button" id="btnNext1" value="生成" type="button" name="btnNext1" runat="server" onserverclick="btnNext1_ServerClick">
<INPUT class="button" id="btnLast" value="最后一页" type="button" name="btnLast" runat="server" onserverclick="btnLast_ServerClick">
<INPUT id="txtGo" size="5" type="text" value="" name="txtGo" runat="server" >
<INPUT class="button" id="btnGo" value="转到" type="button" name="btnGo" runat="server" onserverclick="btnGo_ServerClick"> 共<%=PageCount%>页/第<%=CurrentPage%>页
</TD>
</TR> </TABLE>
<INPUT id="path" type="hidden" size="1" name="path" runat="server">
<INPUT id="ct" type="hidden" size="1" name="ct" runat="server">
<INPUT id="pagecount" type="hidden" size="1" name="pagecount" value="1" runat="server">
<INPUT id="currentpage" type="hidden" size="1" name="currentpage" value="1" runat="server">
<INPUT id="hidFirstpic" type="hidden" size="8" name="hidFirstpic" runat="server">
</form>
</body>
</HTML>