- 注册时间
- 2012-12-12
- 最后登录
- 2013-3-28
- 阅读权限
- 10
- 积分
- 297
- 精华
- 0
- 帖子
- 79
|
factory 发表于 2013-1-17 09:10
能否将你的页面代码贴一下,重现下问题,我本地看下
页面文件:- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="menuinfo.aspx.cs" Inherits="main_jichu_menuinfo" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>菜单信息</title>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
- <link href="../../css/demo.css" rel="stylesheet" type="text/css" />
- <script src="../../scripts/boot.js" type="text/javascript"></script>
- <!--引入皮肤样式-->
- <link href="../../scripts/miniui/themes/blue/skin.css" rel="stylesheet" type="text/css" />
- <link href="../../css/general.css" rel="stylesheet" type="text/css" />
- </head>
- <body>
- <table>
- <tr>
- <td id="label" style ="color:Red; padding-top:10px; width:400px">Menu Manage — 菜单信息</td>
- <td><div id="message" style="color:White; width:150px; text-align:center;"></div></td>
- </tr>
- </table>
- <div style="width:100%;">
- <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
- <table style="width:100%;">
- <tr>
- <td style="width:100%;">
- <%--<a class="mini-button" iconCls="icon-date" onclick="read" plain="true">读取</a>--%>
- <input id="combo" class="mini-combobox" style="width:100;" textField="text" valueField="id"
- data="url" allowInput="true" onvalidation="read" showNullItem="true" nullItemText="请选择..."/>
- <span class="separator"></span>
- <a id="save" class="mini-button" iconCls="icon-save"
- onclick="write" plain="true">保存</a>
- </td>
- </tr>
- </table>
- </div>
- </div>
- <div class="mini-fit" style="height:100px;">
- <textarea id="editor" style="width:100%; height:100%;" class="mini-textarea" vtype="required"></textarea>
- </div>
- <script type="text/javascript">
- var url = [{ id: 1, text: '菜单TXT' }, { id: 2, text: '机组TXT'}, { id: 3, text: '管网TXT'}];
- mini.parse();
- var textarea = mini.get("editor");
- var combo = mini.get("combo");
- function read(){
- var id = combo.getValue();
- var messageid = mini.loading("读取中,请稍后......","Loading");
- $.ajax({
- url:"menuinfo.ashx?method=read&id="+id,
- success:function(text){
- mini.hideMessageBox(messageid);
- if(text=="error"){
- showMessage("数据读取错误");
- }
- else{
- textarea.setValue(text);
- }
- },
- error:function(e,xhr,opt){
- mini.hideMessageBox(messageid);
- mini.alert("[ "+xhr+" ] — 错误状态:"+e.status+",错误信息:"+opt);
- }
- });
- }
-
- function write(){
- var json = textarea.getValue();
- if(json == ""){
- showMessage("数据不能为空");
- }
- else{
- var id = combo.getValue();
- var messageid = mini.loading("保存中,请稍后......","Loading");
- $.ajax({
- url : "menuinfo.ashx?method=write&id="+id,
- data : { data : json },
- type : "post",
- success : function (text){
- if(text=="true")
- showMessage("保存成功");
- else
- showMessage("保存失败");
- mini.hideMessageBox(messageid);
- },
- error: function (jqXHR, textStatus, errorThrown) {
- mini.hideMessageBox(messageid);
- mini.alert(jqXHR.responseText);
- }
- });
- }
- }
- </script>
- </body>
- </html>
复制代码 ashx文件:- <%@ WebHandler Language="C#" Class="menuinfo" %>
- using System;
- using System.Web;
- using System.Collections;
- using System.IO;
- public class menuinfo : IHttpHandler {
- String txtPath = "";
- public void ProcessRequest (HttpContext context) {
- String method = context.Request["method"];
- String id = context.Request["id"];
- switch (id)
- {
- case "1":
- txtPath = HttpContext.Current.Server.MapPath("../../data/menutree.txt");
- break;
- case "2":
- txtPath = HttpContext.Current.Server.MapPath("../../data/jzcount.txt");
- break;
- case "3":
- txtPath = HttpContext.Current.Server.MapPath("../../data/weizhi.txt");
- break;
- }
- switch (method)
- {
- case "read" :
- this.read(context);
- break;
- case "write" :
- this.write(context);
- break;
- }
- }
- public void read(HttpContext context)
- {
- try
- {
- FileStream fs = new FileStream(txtPath, FileMode.Open, FileAccess.Read);
- //FileStream fs = new FileStream(@tB_PachFileName.Text, FileMode.Open, FileAccess.Read);//读取文件设定
- StreamReader m_streamReader = new StreamReader(fs, System.Text.Encoding.GetEncoding("UTF-8"));//设定读写的编码
- //使用StreamReader类来读取文件
- m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
- // 从数据流中读取每一行,直到文件的最后一行,并在rTB_Display.Text中显示出内容
- //this.rTB_Display.Text = "";
- String temp = "";
- string strLine = m_streamReader.ReadLine();
- while (strLine != null)
- {
- temp += strLine + "\n";
- strLine = m_streamReader.ReadLine();
- }
- //关闭此StreamReader对象
- m_streamReader.Close();
- context.Response.Write(temp);
- }
- catch
- {
- //抛出异常
- context.Response.Write("error");
- return;
- }
- }
- public void write(HttpContext context)
- {
- try
- {
- String json = context.Request["data"].ToString();
- FileStream fs = new FileStream(txtPath, FileMode.Create);
- StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("UTF-8"));
- //开始写入
- sw.Write(json);
- //清空缓冲区
- sw.Flush();
- //关闭流
- sw.Close();
- fs.Close();
- context.Response.Write("true");
- }
- catch
- {
- context.Response.Write("error");
- return;
- }
- }
-
- public bool IsReusable {
- get {
- return false;
- }
- }
- }
复制代码 |
|