c# webform js文件获取客户端控件,后台cs获取前台客户端控件的值,c#和js的交互
时间:2010-09-01 来源:我还是不懂
前端的aspx页面写法
<%@ 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" > <script language="JavaScript" type="text/javascript" src="Move.js"></script> <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> <input name="Hidden_name" id="Hidden2" type="hidden" value="" /> <input id="btn" onclick="a()" type=button value="按下" /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div> </form> </body> </html>
给Hidden2控件赋值
// JScript 文件 function a() { document.getElementById("<%=Hidden2.ClientID>").value="456"; }
CS文件
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Response.Write(Request.Form["Hidden_name"].ToString()); } }
相关阅读 更多 +