asp.netajax与jquery和bootstrap的无刷新完美实现
20190421asp.netajax与jquery和bootstrap的无刷新完美实现
设计代码和后台代码中重要部分加粗和深色以及字号加大。
设计前台代码:
<%@ page title="添加/修改商家" language="c#" masterpagefile="~/site_cg007.master" autoeventwireup="true"
codebehind="web_cg007.aspx.cs" inherits="jfydxfjz.web_cg007" enableeventvalidation="false" %>
<asp:content id="content1" contentplaceholderid="head" runat="server">
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>开发者</title>
<script type="text/javascript" src="scripts/bootstrap_v30/jquery/jquery-
1.8.3.min.js"></script>
<script type="text/javascript" src="scripts/layer/layer.js"></script>
<script type="text/javascript" src="scripts/bootstrap_v30/bootstrap/js/bootstrap.min.js"></script>
<link href="stylesheet_dn.css" rel="stylesheet" type="text/css" />
<link href="scripts/bootstrap_v30/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body{color:#686868;}
@media all and (max-width:768px){
p{font-size:12px;}
h2{font-size:16px;}
h3{font-size:14px;}
li{font-size:14px;margin-left:30px;}
.myimg{width:50%;}
}
/*模态窗口取消背景变暗的效果
.modal-backdrop-zrp
{
opacity: 0 !important;
filter: alpha(opacity=0) !important;
}
*/
</style>
</asp:content>
<asp:content id="content2" contentplaceholderid="contentplaceholder1" runat="server">
<asp:scriptmanager id="scriptmanager1" runat="server">
</asp:scriptmanager>
<div class="container">
<div class="row">
<div class="col-md-4 col-xl-12 text-center">
<asp:updateprogress id="updateprogress_gly" runat="server" associatedupdatepanelid="updatepanel_sjgl">
<progresstemplate><asp:image id="image_gly"
cssclass="myimg" runat="server" imageurl="~/images/progress.gif" /></progresstemplate>
</asp:updateprogress>
</div>
</div>
</div>
<asp:updatepanel id="updatepanel_sjgl" runat="server" updatemode="conditional" childrenastriggers="false">
<contenttemplate>
<div class="container">
<center>
<table class="nav-justified">
<tr>
<td style="text-align:left;">
<input type="text" runat="server" id="tbx_kfz_sjqq" placeholder="商家名称或qq" />
</td>
<td>
<asp:button id="btn_kfz_cxsjqq" runat="server" text="查询" cssclass="btn_dn" onclick="btn_kfz_cxsjqq_click" />
</td>
<td>
<button class="btn-primary" data-toggle="modal" data-target="#tjsjmodal" id="btn_html_tj">添加</button>
</td>
<td>
<asp:button id="btn_kfz_tjgly" runat="server" text="添加管理员" cssclass="btn_dn" onclick="btn_kfz_tjgly_click" />
</td>
</tr>
<tr style="text-align:center">
<td colspan="4" style="padding-top:5px;text-align:center">
<!--采用自带的分页功能-->
<center>
<asp:gridview id="gridview_sjgl" runat="server" width="100%" allowpaging="true" autogeneratecolumns="false" cssclass="grid_dn" datakeynames="id" horizontalalign="center" onrowcommand="gridview_sjgl_rowcommand" onrowdatabound="gridview_sjgl_rowdatabound" onpageindexchanging="gridview_sjgl_pageindexchanging">
<columns>
<asp:boundfield datafield="id" headertext="编号">
<headerstyle cssclass="header_dn" />
<itemstyle horizontalalign="left" />
</asp:boundfield>
<asp:boundfield datafield="dwmc" headertext="商家">
<headerstyle cssclass="header_dn" />
<itemstyle horizontalalign="left" />
</asp:boundfield>
<asp:boundfield datafield="sqbh" headertext="授权令">
<headerstyle cssclass="header_dn" />
<itemstyle horizontalalign="left" />
</asp:boundfield>
<asp:templatefield headertext="试用">
<headerstyle cssclass="header_dn" />
<itemtemplate>
<asp:button id="btn_jk_sy" runat="server" text="试用" cssclass="btn"
commandargument='<%# eval("id") %>' commandname="cmn_jz_sy" />
</itemtemplate>
</asp:templatefield>
<asp:templatefield headertext="注册">
<headerstyle cssclass="header_dn" />
<itemtemplate>
<asp:button id="btn_jk_zc" runat="server" text="注册" cssclass="btn"
commandargument='<%# eval("id") %>' commandname="cmn_jz_zc" />
</itemtemplate>
</asp:templatefield>
</columns>
<rowstyle cssclass="row_dn" />
<headerstyle cssclass="header_dn" />
<pagersettings firstpagetext="首页" lastpagetext="尾页" mode="nextpreviousfirstlast" nextpagetext="下页" previouspagetext="上页" />
<pagerstyle horizontalalign="center" />
<selectedrowstyle cssclass="selectrow_dn" />
</asp:gridview>
</center>
</td>
</tr>
</table>
</center>
</div>
<!--添加商家弹出窗口:#tjsjmodal-->
<div id="tjsjmodal" class="modal fade bs-example-modal-sm" data-backdrop="static">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">添加商家</h4>
</div>
<div class="modal-body">
<div class="form-group">
商家名称
<input type="text" runat="server" id="tbx_sjmc" placeholder="输入商家名称" />
</div>
<div class="form-group">
授权口令
<input type="text" runat="server" id="tbx_sqkl" placeholder="输入或者空白" />
</div>
<div class="form-group">
联 系 qq
<input type="text" runat="server" id="tbx_lxqq" placeholder="输入qq号" />
</div>
<div class="form-group">
<asp:label id="lbl_ts" runat="server" forecolor="red" font-size="large" />
</div>
</div>
<div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal">关闭</button>
<asp:button id="btn_gb" cssclass="btn" text="关闭" runat="server" onclick="btn_gb_click" visible="false" />
<asp:button id="btn_tjsj" cssclass="btn" text="添加" runat="server" onclick="btn_tjsj_click" />
</div>
</div>
</div>
</div>
</contenttemplate>
<triggers>
</triggers>
</asp:updatepanel>
</asp:content>
后台代码:
using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using system.data;
using system.data.sqlclient;
namespace jfydxfjz
{
public partial class web_cg007 : system.web.ui.page
{
private jf_cyclxfjzentities sjklj = new jf_cyclxfjzentities();//数据库连接
private webncxk_class gj = new webncxk_class();//加解密工具
protected void page_load(object sender, eventargs e)
{
//加入用户登录认证判断---处理中
cy_kfz db_kfz = session["e1dad727864"] as cy_kfz;
if (db_kfz == null) //不是开发者
{
this.response.redirect("~/default.aspx");
}
if (!page.ispostback) //数据控件绑定数据,必须放入这里,不然每次对数据控件的操作都无效
{
this.gridview_sjgl.datasource = sjklj.cy_sqdw.orderbydescending(aa => aa.id);
this.gridview_sjgl.databind();
}
}
protected void gridview_sjgl_rowcommand(object sender, gridviewcommandeventargs e)
{
try
{
if (e.commandname == "cmn_jz_sy") //单击了试用按钮
{
int id = int.parse(e.commandargument.tostring());
//定位记录
var cxsy = from aa in sjklj.cy_sqdw
where aa.id == id
select aa;
//授权口令生成器
//生成随机试用口令
random sjs = new random(datetime.now.year + datetime.now.month + datetime.now.day + datetime.now.hour + datetime.now.minute +
datetime.now.second + datetime.now.millisecond + 20316);
int scsjs = sjs.next(10000, 99999);
string sqkl = "a" + scsjs.tostring();//试用口令
//没有加密的口令:
string ywkl=sqkl;
sqkl = webncxk_class.encrypt(sqkl, webncxk_class.salt, webncxk_class.jmmy);//加密,自动生成的
if (string.isnullorwhitespace(cxsy.first().sqbh))//没有加入试用口令,正式使用默认30年
{
cxsy.first().sqbh = sqkl;
sjklj.savechanges();
//重新绑定
(e.commandsource as button).text = ywkl;
this.updatepanel_sjgl.update();//有条件更新,而且子控件
// aspnetajaxjavascript.layermsg(this.updatepanel_sjgl, "顾客异步刷新");
return;
}
else
{
//对口令进行解密
string kl = cxsy.first().sqbh.trim();
kl = gj.decrypt(kl, webncxk_class.salt, webncxk_class.jmmy);
if (kl.contains("a"))
{
this.updatepanel_sjgl.update();//有条件更新,而且子控件
aspnetajaxjavascript.layermsg(this.updatepanel_sjgl, "已经是试用了");
return;
}
else
{
cxsy.first().sqbh = sqkl;
sjklj.savechanges();
//重新绑定
(e.commandsource as button).text = ywkl;
this.updatepanel_sjgl.update();//有条件更新,而且子控件
aspnetajaxjavascript.layermsg(this.updatepanel_sjgl, "加入试用成功!");
return;
}
}
}
//注册
if (e.commandname == "cmn_jz_zc") //单击了注册
{
int id = int.parse(e.commandargument.tostring());
//定位记录
var cxsy = from aa in sjklj.cy_sqdw
where aa.id == id
select aa;
//授权口令生成器
//生成随机正式口令
random sjs = new random(datetime.now.year + datetime.now.month + datetime.now.day + datetime.now.hour + datetime.now.minute +
datetime.now.second + datetime.now.millisecond + 20316);
int scsjs = sjs.next(10000, 99999);
string sqkl = "b" + scsjs.tostring();//注册口令
//没有加密的口令:
string ywkl = sqkl;
sqkl = webncxk_class.encrypt(sqkl, webncxk_class.salt, webncxk_class.jmmy);//加密,自动生成的
if (string.isnullorwhitespace(cxsy.first().sqbh))//没有加入正式口令,正式使用默认30年
{
cxsy.first().sqbh = sqkl;
sjklj.savechanges();
//重新绑定
(e.commandsource as button).text = ywkl;
this.updatepanel_sjgl.update();//有条件更新,而且子控件
// aspnetajaxjavascript.layermsg(this.updatepanel_sjgl, "顾客异步刷新");
return;
}
//对口令进行解密
string kl = cxsy.first().sqbh.trim();
kl = gj.decrypt(kl, webncxk_class.salt, webncxk_class.jmmy);
if (kl.contains("b"))
{
this.updatepanel_sjgl.update();//有条件更新,而且子控件
aspnetajaxjavascript.layermsg(this.updatepanel_sjgl, "已经注册成功!");
return;
}
else
{
cxsy.first().sqbh = sqkl;
cxsy.first().yxq = datetime.now.year + 30;
sjklj.savechanges();
//重新绑定
(e.commandsource as button).text = ywkl;
this.updatepanel_sjgl.update();//有条件更新,而且子控件
// aspnetajaxjavascript.layermsg(this.updatepanel_sjgl, "顾客异步刷新");
return;
}
}
}
catch (exception err)
{
this.updatepanel_sjgl.update();//有条件更新,而且子控件
aspnetajaxjavascript.layermsg(this.updatepanel_sjgl, "错误:"+err.message);
}
}
protected void btn_kfz_cxsjqq_click(object sender, eventargs e)
{
// this.updatepanel_sjgl.update();
// aspnetajaxjavascript.layermsg(this.updatepanel_sjgl, "测试查询!");
try
{
string cxtj = this.tbx_kfz_sjqq.value.trim();
if (cxtj == string.empty)
{
this.updatepanel_sjgl.update();//有条件更新,而且子控件
aspnetajaxjavascript.layermsg(this.updatepanel_sjgl, "请输入学校名称或者qq号!");
return;
}
var cxxx = (from aa in sjklj.cy_sqdw
where aa.dwmc.contains(cxtj) || aa.qq.contains(cxtj)
select aa).orderbydescending(bb => bb.id);
this.gridview_sjgl.datasource = cxxx;
this.gridview_sjgl.databind();
this.updatepanel_sjgl.update();//有条件更新,而且子控件
}
catch
{
}
}
protected void gridview_sjgl_rowdatabound(object sender, gridviewroweventargs e)
{
if (e.row.rowtype == datacontrolrowtype.datarow)
{
try
{
int id = int.parse(this.gridview_sjgl.datakeys[e.row.rowindex].value.tostring());//获取主键
//获取加密的授权口令
string sqkl = sjklj.cy_sqdw.where(aa => aa.id == id).first().sqbh;
sqkl = gj.decrypt(sqkl, webncxk_class.salt, webncxk_class.jmmy);//解密
// this.gv_xx.rows[e.row.rowindex].cells[2].text = sqkl;//出错,索引找不到
e.row.cells[2].text = sqkl;
}
catch
{
}
}
}
protected void gridview_sjgl_pageindexchanging(object sender, gridviewpageeventargs e)
{
this.gridview_sjgl.pageindex = e.newpageindex;
this.gridview_sjgl.datasource = sjklj.cy_sqdw.orderbydescending(aa => aa.id);
this.gridview_sjgl.databind();
//刷新
this.updatepanel_sjgl.update();
}
protected void btn_kfz_tjgly_click(object sender, eventargs e)
{
try
{
//123加密为初始密码
string jbmm = webncxk_class.encrypt("123", webncxk_class.salt, webncxk_class.jmmy);
//查看管理员是否还没有添加,查找在管理员表中没有的xk_sqdw记录
var cxmygly = from aa in sjklj.cy_sqdw
where !sjklj.admin_user.any(bb => bb.dwid == aa.id)
select aa;//这个方法很不错
random sjs = new random(datetime.now.year + datetime.now.month + datetime.now.day + datetime.now.hour + datetime.now.minute +
datetime.now.second + datetime.now.millisecond + 20316);
foreach (var kk in cxmygly)
{
int scsjs = sjs.next(1000, 9999);
admin_user tj_gly = new admin_user
{
dwid = kk.id,
yhm =kk.id.tostring()+"a"+scsjs.tostring(),//按照a分割出dwid
mm = jbmm
};
sjklj.admin_user.addobject(tj_gly);
}
sjklj.savechanges();
//layeriujq.msg("管理员添加完成", "6", "3000", this.page);
this.updatepanel_sjgl.update();//有条件更新,而且子控件
aspnetajaxjavascript.layermsg(this.updatepanel_sjgl, "管理员添加完成!");
return;
}
catch
{
}
}
protected void btn_tjsj_click(object sender, eventargs e)
{
try
{
//只需要商家名称和qq号
string sjmc = this.tbx_sjmc.value.trim();
string qq = this.tbx_lxqq.value.trim();
string sqxx = this.tbx_sqkl.value.trim();
//生成随机试用口令
random sjs = new random(datetime.now.year + datetime.now.month + datetime.now.day + datetime.now.hour + datetime.now.minute +
datetime.now.second + datetime.now.millisecond + 20316);
int scsjs = sjs.next(10000, 99999);
string sqkl = "a" + scsjs.tostring();//试用口令
&nb
推荐阅读