用AJAX前台获取后台.cs数值
aspx:
function select (price)
{
var param = "option=select&price=" + price;
var options =
{
method: 'post', parameters: param, onComplete:
function(transport) {
var retv = transport.responseText; //获取到得值
}
}
new Ajax.Request('index.aspx', options); // index.aspx 为当前页面
}
.cs
if(Request.Form["option"] != null && Request.Form["option"].Trim().Equals("select"))
{
Response.Write(...); //通过Response将数据传给.aspx页面
Response.End();
return;
}
以上代码的原理为 1 .aspx页面写好AJAX方法来获取后台数据 2 .cs文件获取页面要显示的数据 通过AJAX的Response.Write()方法传给前台页面
以下为项目部分源码
if (Request.Form["Option"] != null && Request.Form["Option"].Trim().Equals("select"))
{
string where = string.Empty;
string prices = Request.Form["price"].ToString().Trim();
string[] price = prices.Split('-');
if (prices=="0")
{
where = "";
}
else if (price.Length>1)
{
where = " and price between " + price[0] + " and " + price[1]+" ";
}
else
{
where = " and price > 5000 ";
}
StringBuilder sb = BindProductBySearch(where); //StringBuilder sb来接收下面方法的返回值
Response.Write(sb.ToString()); //将sb传给前台页面
Response.End();
return;
}
private StringBuilder BindProductBySearch(string strwhere)
{
BLL.Shop.ShopProduct shopbll = new BLL.Shop.ShopProduct();
SqlDataReader reader = shopbll.GetProductForIndex(strwhere);
StringBuilder products = new StringBuilder();
string style = " style=\"margin-left:0\" ";
int count = 1;
while (reader.Read())
{
string imageUrl = reader["images"].ToString().Trim();
string ppxh = reader["PPXH"].ToString().Trim();//品牌
string price = Convert.ToInt32(reader["Price"]).ToString();
string model = reader["Model"].ToString();
string id = Convert.ToInt32(reader["id"]).ToString();
string pm = TelRen.Common.PubUtil.SubStringTen(ppxh + " " + model, 10);
string condition = reader["condition"].ToString();
products.Append("<div class=\"main_pro_box\" ");
if(count%6==1)
{
products.Append(style);
}
products.Append(">\n");
products.Append("<a href=\"membercenter/pro_show_" + id + "_1.html\"><img src=\"" + imageUrl + "\" width=\"102px\" height=\"102px\" /></a>\n");
products.Append("<br /><b style=\"color:#FF3300\"><b style=\"color:#666666\">¥</b>" + price + "</b><br />\n");
products.Append("<span style=\"color:#0045DF\">"+pm+"<br />\n");
products.Append("成色:"+condition+"</span></div>\n");
count++;
}
reader.Close();
reader.Dispose();
reader = null;
return products;
}用AJAX前台获取后台.cs数值
用AJAX前台获取后台.cs数值
aspx:
function select (price)
{
var param = "option=select&price=" + price;
var options =
{
method: 'post', parameters: param, onComplete:
function(transport) {
var retv = transport.responseText; //获取到得值
}
}
new Ajax.Request('index.aspx', options); // index.aspx 为当前页面
}
.cs
if(Request.Form["option"] != null && Request.Form["option"].Trim().Equals("select"))
{
Response.Write(...); //通过Response将数据传给.aspx页面
Response.End();
return;
}
以上代码的原理为 1 .aspx页面写好AJAX方法来获取后台数据 2 .cs文件获取页面要显示的数据 通过AJAX的Response.Write()方法传给前台页面
以下为项目部分源码
if (Request.Form["Option"] != null && Request.Form["Option"].Trim().Equals("select"))
{
string where = string.Empty;
string prices = Request.Form["price"].ToString().Trim();
string[] price = prices.Split('-');
if (prices=="0")
{
where = "";
}
else if (price.Length>1)
{
where = " and price between " + price[0] + " and " + price[1]+" ";
}
else
{
where = " and price > 5000 ";
}
StringBuilder sb = BindProductBySearch(where); //StringBuilder sb来接收下面方法的返回值
Response.Write(sb.ToString()); //将sb传给前台页面
Response.End();
return;
}
private StringBuilder BindProductBySearch(string strwhere)
{
BLL.Shop.ShopProduct shopbll = new BLL.Shop.ShopProduct();
SqlDataReader reader = shopbll.GetProductForIndex(strwhere);
StringBuilder products = new StringBuilder();
string style = " style=\"margin-left:0\" ";
int count = 1;
while (reader.Read())
{
string imageUrl = reader["images"].ToString().Trim();
string ppxh = reader["PPXH"].ToString().Trim();//品牌
string price = Convert.ToInt32(reader["Price"]).ToString();
string model = reader["Model"].ToString();
string id = Convert.ToInt32(reader["id"]).ToString();
string pm = TelRen.Common.PubUtil.SubStringTen(ppxh + " " + model, 10);
string condition = reader["condition"].ToString();
products.Append("<div class=\"main_pro_box\" ");
if(count%6==1)
{
products.Append(style);
}
products.Append(">\n");
products.Append("<a href=\"membercenter/pro_show_" + id + "_1.html\"><img src=\"" + imageUrl + "\" width=\"102px\" height=\"102px\" /></a>\n");
products.Append("<br /><b style=\"color:#FF3300\"><b style=\"color:#666666\">¥</b>" + price + "</b><br />\n");
products.Append("<span style=\"color:#0045DF\">"+pm+"<br />\n");
products.Append("成色:"+condition+"</span></div>\n");
count++;
}
reader.Close();
reader.Dispose();
reader = null;
return products;
}用AJAX前台获取后台.cs数值
用AJAX前台获取后台.cs数值
aspx:
function select (price)
{
var param = "option=select&price=" + price;
var options =
{
method: 'post', parameters: param, onComplete:
function(transport) {
var retv = transport.responseText; //获取到得值
}
}
new Ajax.Request('index.aspx', options); // index.aspx 为当前页面
}
.cs
if(Request.Form["option"] != null && Request.Form["option"].Trim().Equals("select"))
{
Response.Write(...); //通过Response将数据传给.aspx页面
Response.End();
return;
}
以上代码的原理为 1 .aspx页面写好AJAX方法来获取后台数据 2 .cs文件获取页面要显示的数据 通过AJAX的Response.Write()方法传给前台页面
以下为项目部分源码
if (Request.Form["Option"] != null && Request.Form["Option"].Trim().Equals("select"))
{
string where = string.Empty;
string prices = Request.Form["price"].ToString().Trim();
string[] price = prices.Split('-');
if (prices=="0")
{
where = "";
}
else if (price.Length>1)
{
where = " and price between " + price[0] + " and " + price[1]+" ";
}
else
{
where = " and price > 5000 ";
}
StringBuilder sb = BindProductBySearch(where); //StringBuilder sb来接收下面方法的返回值
Response.Write(sb.ToString()); //将sb传给前台页面
Response.End();
return;
}
private StringBuilder BindProductBySearch(string strwhere)
{
BLL.Shop.ShopProduct shopbll = new BLL.Shop.ShopProduct();
SqlDataReader reader = shopbll.GetProductForIndex(strwhere);
StringBuilder products = new StringBuilder();
string style = " style=\"margin-left:0\" ";
int count = 1;
while (reader.Read())
{
string imageUrl = reader["images"].ToString().Trim();
string ppxh = reader["PPXH"].ToString().Trim();//品牌
string price = Convert.ToInt32(reader["Price"]).ToString();
string model = reader["Model"].ToString();
string id = Convert.ToInt32(reader["id"]).ToString();
string pm = TelRen.Common.PubUtil.SubStringTen(ppxh + " " + model, 10);
string condition = reader["condition"].ToString();
products.Append("<div class=\"main_pro_box\" ");
if(count%6==1)
{
products.Append(style);
}
products.Append(">\n");
products.Append("<a href=\"membercenter/pro_show_" + id + "_1.html\"><img src=\"" + imageUrl + "\" width=\"102px\" height=\"102px\" /></a>\n");
products.Append("<br /><b style=\"color:#FF3300\"><b style=\"color:#666666\">¥</b>" + price + "</b><br />\n");
products.Append("<span style=\"color:#0045DF\">"+pm+"<br />\n");
products.Append("成色:"+condition+"</span></div>\n");
count++;
}
reader.Close();
reader.Dispose();
reader = null;
return products;
}用AJAX前台获取后台.cs数值
用AJAX前台获取后台.cs数值
aspx:
function select (price)
{
var param = "option=select&price=" + price;
var options =
{
method: 'post', parameters: param, onComplete:
function(transport) {
var retv = transport.responseText; //获取到得值
}
}
new Ajax.Request('index.aspx', options); // index.aspx 为当前页面
}
.cs
if(Request.Form["option"] != null && Request.Form["option"].Trim().Equals("select"))
{
Response.Write(...); //通过Response将数据传给.aspx页面
Response.End();
return;
}
以上代码的原理为 1 .aspx页面写好AJAX方法来获取后台数据 2 .cs文件获取页面要显示的数据 通过AJAX的Response.Write()方法传给前台页面
以下为项目部分源码
if (Request.Form["Option"] != null && Request.Form["Option"].Trim().Equals("select"))
{
string where = string.Empty;
string prices = Request.Form["price"].ToString().Trim();
string[] price = prices.Split('-');
if (prices=="0")
{
where = "";
}
else if (price.Length>1)
{
where = " and price between " + price[0] + " and " + price[1]+" ";
}
else
{
where = " and price > 5000 ";
}
StringBuilder sb = BindProductBySearch(where); //StringBuilder sb来接收下面方法的返回值
Response.Write(sb.ToString()); //将sb传给前台页面
Response.End();
return;
}
private StringBuilder BindProductBySearch(string strwhere)
{
BLL.Shop.ShopProduct shopbll = new BLL.Shop.ShopProduct();
SqlDataReader reader = shopbll.GetProductForIndex(strwhere);
StringBuilder products = new StringBuilder();
string style = " style=\"margin-left:0\" ";
int count = 1;
while (reader.Read())
{
string imageUrl = reader["images"].ToString().Trim();
string ppxh = reader["PPXH"].ToString().Trim();//品牌
string price = Convert.ToInt32(reader["Price"]).ToString();
string model = reader["Model"].ToString();
string id = Convert.ToInt32(reader["id"]).ToString();
string pm = TelRen.Common.PubUtil.SubStringTen(ppxh + " " + model, 10);
string condition = reader["condition"].ToString();
products.Append("<div class=\"main_pro_box\" ");
if(count%6==1)
{
products.Append(style);
}
products.Append(">\n");
products.Append("<a href=\"membercenter/pro_show_" + id + "_1.html\"><img src=\"" + imageUrl + "\" width=\"102px\" height=\"102px\" /></a>\n");
products.Append("<br /><b style=\"color:#FF3300\"><b style=\"color:#666666\">¥</b>" + price + "</b><br />\n");
products.Append("<span style=\"color:#0045DF\">"+pm+"<br />\n");
products.Append("成色:"+condition+"</span></div>\n");
count++;
}
reader.Close();
reader.Dispose();
reader = null;
return products;
}