我的javascript的onclick事件中调用c#代码,可是我观察执行顺序的时候,为啥c#中的代码先执行呢?

a2325145 2012-06-06 12:35:26
我的javascript的onclick事件中调用c#代码,可是我观察执行顺序的时候,为啥c#中的代码先执行呢?
我在html中调用吃c#写的代码,执行的顺序也是c#的先执行呢?求哪位大神讲解一下执行的具体顺序
...全文
176 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2012-06-06
  • 打赏
  • 举报
回复
$("a[name='a2']").click(function () {
<%Delete();%>
})

这样的代码错误的

你应该
$("a[name='a2']").click(function () {
ajax.get(url)//删除内容
})

或者采用回调函数的方法
孟子E章 2012-06-06
  • 打赏
  • 举报
回复
生成表格GridView不是很方便的吗?为啥要自己拼接html啊
孟子E章 2012-06-06
  • 打赏
  • 举报
回复
Web程序就是这样的,服务端代码全部执行完毕,才发送到客户端,客户端才能显示内容的,你要搞清楚
a2325145 2012-06-06
  • 打赏
  • 举报
回复
代码已经贴出一个前台的一个是后台的。
a2325145 2012-06-06
  • 打赏
  • 举报
回复
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Stationtype.aspx.cs" Inherits="WebDemo.Stationtype" %>

<!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 runat="server">
<title></title>
<style type="text/css">
.dh
{
margin: 10px;
padding: 5px;
font-weight: 600;
}
.dh a
{
color: #000;
text-decoration: none;
}
.dh a:hover
{
color: #CC3333;
}
.SetTableDis
{
margin-left: 20px;
border-collapse: collapse;
}
.SetTable td
{
padding: 10px 3px;
font-size: 14px;
}
.SetTable input, .SetTable textarea
{
padding: 1px;
font-size: 13px;
}

.SetTableDis
{
margin-left: 20px;
border-collapse: collapse;
}
.SetTableDis th
{
padding: 10px 8px;
background: #cccc99;
}
.SetTableDis td
{
padding: 10px 8px;
font-size: 14px;
}
</style>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">

$(function () {

$("a[name='a1']").click(function () {

})
$("a[name='a2']").click(function () {
<%Delete();%>
})

})

</script>
</head>
<body>
<div class="dh">
参数设置 -> <a href="SetSta.asp?ParaType=Sta">小区操作</a>
</div>
<div id="cover">
</div>
<div id="xiugai" style="display: none">
<table>
<tr>
<td>
站点的内容:
</td>
</tr>
</table>
</div>
<%=Change() %>
<div id="place">

<table class="SetTableDis" border="1" bordercolor="#CC9933">
<tbody>
<tr>
<th>
小区编号
</th>
<th>
小区名称
</th>
<th>
操作
</th>
<th>
查看
</th>
</tr>
<%= GetList()%>
</tbody>
</table>
<table class="SetTable" border="0">
<form method="post" runat="server" name="name1">
<tbody>
<tr>
<td>
   站点类型名称
</td>
<td>
<input type="text" id="Typename" name="Typename">
</td>
<td>
<input type="submit" value="添加">
</td>
</tr>
</tbody>
<input type="hidden" id="ParaType" name="ParaType" value="Sta"><input type="hidden"
id="action" name="action" value="add">
</form>
</table>
</div>
<div>
<%-- <%--<form name="from1" action="Stationtype.aspx?" method="post">
<table>
<tr>
<td>
站点类型名称
</td>
</tr>
</table>
<input type="text" value="<%= %>"/>
<input type="submit" value="提交" />
</form>--%>
<%-- <%=Change() %>--%>--%>
</div>
</body>
</html>
a2325145 2012-06-06
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebDemo
{
public partial class Stationtype : System.Web.UI.Page
{
public string type;

protected void Page_Load(object sender, EventArgs e)
{

if (IsPostBack)
{ //添加数据
string typename = Context.Request.Form["Typename"];

Maticsoft.BLL.Stationtype stationtypeBll = new Maticsoft.BLL.Stationtype();
Maticsoft.Model.Stationtype stationtypeModel = new Maticsoft.Model.Stationtype();
if (string.IsNullOrEmpty(typename))
{

this.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), "alert('添加内容不能为空');", true);
//Response.Write("<script type='text/javascript'>alert('添加内容不能为空');</script>");
return;

}
stationtypeModel.TypeName = typename;

int count = stationtypeBll.Add(stationtypeModel);
if (count != 0)
{
this.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), "alert('添加成功');", true);


}
else
{
this.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), "alert('添加失败');", true);

}

}


}
public string GetList()
{
//读取数据表Stationtype


Maticsoft.BLL.Stationtype stationtype = new Maticsoft.BLL.Stationtype();
List<Maticsoft.Model.Stationtype> stationtupeList = stationtype.GetModelList("");
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for (int i = 0; i < stationtupeList.Count; i++)
{
Maticsoft.Model.Stationtype model = stationtupeList[i];
sb.Append("<tr>");
sb.Append("<th>" + model.TypeID + "</th>");
sb.Append("<th>" + model.TypeName + "</th>");
sb.Append("<th>");
sb.Append(" <a href='Stationtype.aspx?id=" + model.TypeID + "&type=chage'id='xiugai' name='a1'>修改</a>" + " <a href='Stationtype.aspx?id=" + model.TypeID + "&type=del' name='a2' >删除</a> ");

sb.Append("</th>");
sb.Append("<th>");
sb.Append("<a href=''>查看所属用热户</a>");
sb.Append("</th>");
sb.Append("</tr>");

}
return sb.ToString();
}
public string Change()
{


string s = "";
string id = Context.Request.QueryString["id"];
string chage = Context.Request.QueryString["type"];

if (id != null && chage == "chage")
{
Maticsoft.BLL.Stationtype bll = new Maticsoft.BLL.Stationtype();
Maticsoft.Model.Stationtype model = bll.GetModel(int.Parse(id));
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<div>");
sb.Append("<form name='from2' action='Stationtype.aspx?id=' method='get'");
sb.Append(" <table>");
sb.Append(" <tr>");
sb.Append("<td>" + " " + " " + " " + " " + " " + "站点类型名称:");
sb.Append("</td>");
sb.Append("</tr>");
sb.Append("</table>");
sb.Append("<input type='text' value='" + model.TypeName + "' style='text-align' name='tijiao'/>");
sb.Append("<input type='submit' value='提交' id='name'");
sb.Append("</form>");
sb.Append("</div>");
return sb.ToString();
// <input type="text" value="<%=type %>"/>
//<input type="submit" value="提交" />

}
else
{
return s;
}


}
public void Delete()
{
this.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), "alert('测试代码');", true);
string id = Context.Request.QueryString["id"];
string type = Context.Request.QueryString["type"];
if (id != null && type == "del")
{
Maticsoft.BLL.Stationtype bll = new Maticsoft.BLL.Stationtype();
if (bll.Delete(int.Parse(id)))
{

this.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), "alert('删除成功');", true);
}
else
{
this.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), "alert('删除失败');", true);
}

}

}
//public void Tijiao()
////{
//// string id = Context.Request.QueryString["id"];
//// Maticsoft.BLL.Stationtype bll = new Maticsoft.BLL.Stationtype();
//// Maticsoft.Model.Stationtype modell = bll.GetModel(int.Parse(id));
//// modell.TypeName=




//}

}
}
天下如山 2012-06-06
  • 打赏
  • 举报
回复
麻烦贴出 具体代码吧。
cnfixit 2012-06-06
  • 打赏
  • 举报
回复
asp.net不是在服务端执行的吗,服务端执行完毕返回结果给浏览器,web菜鸟意见

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧