`
datoplay
  • 浏览: 1614648 次
文章分类
社区版块
存档分类
最新评论

js调用后台的方法

 
阅读更多

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>

<script>
function upd() {
var d = document.forms(0);
d.operation.value = "update";
d.submit();
}

function getValue() {
var d = document.forms(0);
d.operation.value = "getValue";
d.submit();
}

</script>

</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div>
<input type="hidden" name="operation" value="" />
<input type="button" value="update" onclick="upd()" />
<br />
<br />
begin:
<asp:TextBox ID="txt_begin" runat="server" />
<input type="button" value="getValue" onclick="getValue();" />
after:
<asp:TextBox ID="txt_end" runat="server" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string operation = Request["operation"];
switch (operation)
{
case "update":
update();
break;
case "getValue":
getValue();
break;
}
}

private void getValue()
{
txt_end.Text = txt_begin.Text;
UpdatePanel1.Update();
}

private void update()
{
Response.Write("this is update method");
}
}

方法二:

1protectedstringCsharpVoid(stringstrCC)
2{
3strCC="你好!"+strCC;
4returnstrCC;
5}

前台JS

1functionInit()
2{
3varv="中国";
4vars='<%=CsharpVoid("'+v+'")%>';
5alert(s);
6}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics