一个关于预编译和动态编译的问题
是这样的,我一直以来都是用记事本写的页面,把代码和html写在一个文件里,而不是分开写在.aspx和.aspx.cs文件里
我都是这种格式:
<%@ Page Language="VB" %>
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.Sqlclient"%>
<script language="vb" runat="server">
Sub uad(ByVal sender As Object, ByVal e As EventArgs)
Dim i As Int32
Dim con As SqlConnection
Dim strcmd As String
Dim cmd As SqlCommand
i = Request("favtpid")
con = New SqlConnection(ConfigurationSettings.AppSettings("books"))
strcmd = "insert into fav (favtpid,favt,favadd) values (@favtpid,@favt,@favadd)"
cmd = New SqlCommand(strcmd, con)
cmd.Parameters.Add("@favtpid", SqlDbType.Int).Value = i
cmd.Parameters.Add("@favt", SqlDbType.VarChar).Value = nm.Text
cmd.Parameters.Add("@favadd", SqlDbType.VarChar).Value = addr.Text
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Response.Redirect("fave.aspx?favtpid=" & i)
End Sub
Sub retbt(ByVal sender As Object, ByVal e As EventArgs)
Dim i As Int32
i = Request("favtpid")
Response.Redirect("fave.aspx?favtpid=" & i)
End Sub
</script>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta charset="utf-8" />
<title></title>
</head>
<body style="font-size:13px;">
<form id="form1" runat="server" autocomplete="off">
<div>
<br><br>网站名称<asp:textbox ID="nm" runat="server" Style="width:260px;"/><br><br>网站地址<asp:textbox ID="addr" runat="server" text="http://" Style="width:260px;"/><br><br><asp:button ID="addradd" runat="server" Text="添加网址" OnClick="uad"/> <asp:button ID="ret" runat="server" Text="返回" OnClick="retbt"/>
</div>
</form>
</body>
</html>
现在有一个ashx文件,是别人帮我写的,但是分成了两个文件Handler1.ashx和Handler1.ashx.cs,而且需要vs编译,感觉用起来不方便,项请各位帮忙帮我把两个文件合并成一个,就像我自己的风格,也可以不用vs编译,谢谢
Handler1.ashx内容:
<%@ WebHandler Language="C#" CodeBehind="Handler1.ashx.cs" Class="web.Handler1" %>
Handler1.ashx.cs内容:
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
namespace web
{
/// <summary>
/// Handler1 的摘要说明
/// </summary>
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string action = context.Request["action"].ToString();
switch (action)
{
//获取绑定的排序id集合
case "GetOrderIds":
GetOrderIds(context);
break;
//更新绑定的排序id集合
case "UpdateOrderIds":
UpdateOrderIds(context);
break;
}
}
public void GetOrderIds(HttpContext context)
{
int userId = 001; //模拟用户id
string sql = "select * from px where uid = " + userId;
SqlHelper sqlHelper = new SqlHelper();
DataTable dt = sqlHelper.ExecuteQuery(sql);
string orderIds = "";
if (dt.Rows.Count > 0)
{
orderIds = dt.Rows[0]["orders"].ToString();
}
context.Response.Clear();
context.Response.ContentType = "text/plain";
context.Response.Write(orderIds);
}
public void UpdateOrderIds(HttpContext context)
{
int userId = 001; //模拟用户id
string orderIds = context.Request["orderIds"].ToString();
string s_sql = "select * from px where uid = " + userId;
SqlHelper sqlHelper = new SqlHelper();
DataTable dt = sqlHelper.ExecuteQuery(s_sql);
string sql = "";
if (dt.Rows.Count > 0) //判断数据库中是否存在此用户的排序字段。存在更新,否则执行添加
{
sql = "update px set orders='" + orderIds + "' where uid=" + userId;
}
else {
sql = "insert into px values(" + userId + ",'" + orderIds + "')";
}
int i = sqlHelper.ExecuteNonQuery(sql);
context.Response.Clear();
context.Response.ContentType = "text/plain";
if (i > 0)
{
context.Response.Write("1");
}
else
{
context.Response.Write("0");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}