<%@ 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");
}
}
方法二:
protected
string
CsharpVoid(
string
strCC)2

{3
strCC="你好!"+strCC;4
returnstrCC;5
}
前台JS
functionInit()2
{3
varv="中国";4
vars='
<%
=
CsharpVoid(
"
'+v+'
"
)
%>
';5
alert(s);6
}
本文介绍了一个简单的ASP.NET示例,展示了如何通过客户端JavaScript触发服务器端C#代码来更新网页内容及获取表单输入值。具体实现包括使用UpdatePanel进行局部刷新,并通过隐藏字段传递操作指令。
1784

被折叠的 条评论
为什么被折叠?



